mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 23:33:58 +01:00
Compare commits
No commits in common. "558ea897223eec81dedba76cea7c3ec78baf2331" and "ea35674853f1672a71726a16a3c5f30a30b40402" have entirely different histories.
558ea89722
...
ea35674853
|
@ -18,6 +18,7 @@ bonuses:
|
||||||
helper: 0.4
|
helper: 0.4
|
||||||
booster: 0.5
|
booster: 0.5
|
||||||
|
|
||||||
|
# discord reward 0.99^lvl?
|
||||||
|
|
||||||
rewards:
|
rewards:
|
||||||
day: 250 # scales with level. More in ../../credit_management/settings.py
|
day: 250
|
||||||
|
|
|
@ -86,7 +86,6 @@ async def stream(
|
||||||
'Sorry, the API has no working keys anymore.',
|
'Sorry, the API has no working keys anymore.',
|
||||||
'The admins have been messaged automatically.'
|
'The admins have been messaged automatically.'
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
for k, v in target_request.get('headers', {}).items():
|
for k, v in target_request.get('headers', {}).items():
|
||||||
headers[k] = v
|
headers[k] = v
|
||||||
|
@ -139,7 +138,6 @@ async def stream(
|
||||||
chunk = f'{chunk.decode("utf8")}\n\n'
|
chunk = f'{chunk.decode("utf8")}\n\n'
|
||||||
chunk = chunk.replace(os.getenv('MAGIC_WORD', 'novaOSScheckKeyword'), payload['model'])
|
chunk = chunk.replace(os.getenv('MAGIC_WORD', 'novaOSScheckKeyword'), payload['model'])
|
||||||
# chunk = chunk.replace(os.getenv('MAGIC_USER_WORD', 'novaOSSuserKeyword'), user['_id'])
|
# chunk = chunk.replace(os.getenv('MAGIC_USER_WORD', 'novaOSSuserKeyword'), user['_id'])
|
||||||
print(chunk)
|
|
||||||
|
|
||||||
if not chunk.strip():
|
if not chunk.strip():
|
||||||
send = False
|
send = False
|
||||||
|
@ -147,6 +145,7 @@ async def stream(
|
||||||
if is_chat and '{' in chunk:
|
if is_chat and '{' in chunk:
|
||||||
data = json.loads(chunk.split('data: ')[1])
|
data = json.loads(chunk.split('data: ')[1])
|
||||||
send = True
|
send = True
|
||||||
|
print(data)
|
||||||
|
|
||||||
if target_request['module'] == 'twa' and data.get('text'):
|
if target_request['module'] == 'twa' and data.get('text'):
|
||||||
chunk = chat.create_chat_chunk(
|
chunk = chat.create_chat_chunk(
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
async def get_all_users(client):
|
|
||||||
users = client['nova-core']['users']
|
|
||||||
return users
|
|
||||||
|
|
||||||
async def update_credits(users, settings = None):
|
|
||||||
if not settings:
|
|
||||||
users.update_many({}, {"$inc": {"credits": 250}})
|
|
||||||
|
|
||||||
else:
|
|
||||||
for key, value in settings.items():
|
|
||||||
users.update_many({'role': key}, {"$inc": {"credits": int(value)}})
|
|
||||||
print(f"Updated {key} to {value}")
|
|
|
@ -1,51 +0,0 @@
|
||||||
import asyncio
|
|
||||||
from settings import roles
|
|
||||||
import autocredits
|
|
||||||
import aiohttp
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import os
|
|
||||||
import pymongo
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
CONNECTION_STRING = os.getenv("CONNECTION_STRING")
|
|
||||||
pymongo_client = pymongo.MongoClient(CONNECTION_STRING)
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
users = await autocredits.get_all_users(pymongo_client)
|
|
||||||
|
|
||||||
await update_roles(users)
|
|
||||||
await autocredits.update_credits(users, roles)
|
|
||||||
|
|
||||||
async def update_roles(users):
|
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
try:
|
|
||||||
async with session.get('http://localhost:50000/get_roles') as response:
|
|
||||||
data = await response.json()
|
|
||||||
except aiohttp.ClientError as e:
|
|
||||||
print(f"Error: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
lvlroles = [f"lvl{lvl}" for lvl in range(10, 110, 10)] + ['']
|
|
||||||
discord_users = data
|
|
||||||
users = await autocredits.get_all_users(pymongo_client)
|
|
||||||
|
|
||||||
filtered_users = users.find({'role': {'$in': lvlroles}})
|
|
||||||
|
|
||||||
bulk_updates = []
|
|
||||||
for user in filtered_users:
|
|
||||||
discord = str(user['auth']['discord'])
|
|
||||||
|
|
||||||
for id_, roles in discord_users.items():
|
|
||||||
if id_ == discord:
|
|
||||||
for role in lvlroles:
|
|
||||||
if role in roles:
|
|
||||||
bulk_updates.append(pymongo.UpdateOne({'auth.discord': int(discord)}, {'$set': {'role': role}}))
|
|
||||||
print(f"Updated {id_} to {role}")
|
|
||||||
break
|
|
||||||
if bulk_updates:
|
|
||||||
with pymongo_client:
|
|
||||||
users.bulk_write(bulk_updates)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
|
@ -1,38 +0,0 @@
|
||||||
import nextcord
|
|
||||||
import aiohttp.web
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
import os
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
TOKEN = os.getenv("BOT_TOKEN")
|
|
||||||
GUILD_ID = os.getenv("GUILD_ID")
|
|
||||||
|
|
||||||
client = nextcord.Client(intents=nextcord.Intents.all())
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_ready():
|
|
||||||
# start webserver using aiohttp
|
|
||||||
app = aiohttp.web.Application()
|
|
||||||
|
|
||||||
async def get_roles(request):
|
|
||||||
return aiohttp.web.json_response(await get_userinfo())
|
|
||||||
|
|
||||||
app.router.add_get('/get_roles', get_roles)
|
|
||||||
|
|
||||||
runner = aiohttp.web.AppRunner(app)
|
|
||||||
await runner.setup()
|
|
||||||
site = aiohttp.web.TCPSite(runner, 'localhost', 50000)
|
|
||||||
await site.start()
|
|
||||||
|
|
||||||
print('Bot is ready')
|
|
||||||
|
|
||||||
|
|
||||||
async def get_userinfo():
|
|
||||||
guild = client.get_guild(int(GUILD_ID))
|
|
||||||
members = guild.members
|
|
||||||
|
|
||||||
user_roles = {member.id: [role.name for role in member.roles] for member in members}
|
|
||||||
return user_roles
|
|
||||||
|
|
||||||
client.run(TOKEN)
|
|
|
@ -1,13 +0,0 @@
|
||||||
roles = {
|
|
||||||
'': '250',
|
|
||||||
'lvl10': '280',
|
|
||||||
'lvl20': '310',
|
|
||||||
'lvl30': '340',
|
|
||||||
'lvl40': '370',
|
|
||||||
'lvl50': '400',
|
|
||||||
'lvl60': '430',
|
|
||||||
'lvl70': '460',
|
|
||||||
'lvl80': '490',
|
|
||||||
'lvl90': '520',
|
|
||||||
'lvl100': '550',
|
|
||||||
}
|
|
Loading…
Reference in a new issue