diff --git a/cord/accounts.py b/cord/accounts.py index 506e9b9..984a4a2 100644 --- a/cord/accounts.py +++ b/cord/accounts.py @@ -52,6 +52,9 @@ Learn more about how to use our API at **https://nova-oss.com**. async def get_credits(interaction): account = await get_account(interaction) + if not account: + return + amount_credits = account["credits"] await embedder.info(interaction, f"""### Your credits @@ -59,7 +62,7 @@ Amount: **{amount_credits if amount_credits < 1000000 else '∞'}** """, ephemeral=True) async def get_credits_of(interaction, user): - if "Maintainer" not in interaction.user.roles: + if not interaction.user.guild_permissions.administrator: await embedder.error(interaction, """Sorry, you don't have the permission to do that.""", ephemeral=True) return @@ -80,4 +83,42 @@ Please report this issue to the staff!""", ephemeral=True) await embedder.info(interaction, f"""### Credits of {user.name} Amount: **{amount_credits if amount_credits < 1000000 else '∞'}** -""", ephemeral=True) \ No newline at end of file +""", ephemeral=True) + +async def set_credits(interaction, user, amount): + if not interaction.user.guild_permissions.administrator: + await embedder.error(interaction, """Sorry, you don't have the permission to do that.""", ephemeral=True) + return + + try: + userinfo = await request_user_by_discord_id(user.id) + + except Exception as exc: + await embedder.error(interaction, """Sorry, there was an error while checking if you have an account. +Please report this issue to the staff!""", ephemeral=True) + raise exc + + if userinfo.status_code == 404: + await embedder.error(interaction, """You don't have an account yet!""", ephemeral=True) + return + + account = userinfo.json() + account["credits"] = amount + + try: + requests.put( + url=f'https://api.nova-oss.com/users?discord_id={account["auth"]["discord"]}', + timeout=3, + headers={ + 'Content-Type': 'application/json', + 'Authorization': os.getenv('CORE_API_KEY') + }, + data=json.dumps(account) + ) + + except Exception as exc: + await embedder.error(interaction, """Sorry, there was an error while setting your credits. +Please report this issue to the staff!""", ephemeral=True) + raise exc + + await embedder.ok(interaction, f"""Successfully set the credits of {user.name} to **{amount}**.""", ephemeral=True) diff --git a/cord/autochat.py b/cord/autochat.py index 236c9dc..d4031f9 100644 --- a/cord/autochat.py +++ b/cord/autochat.py @@ -14,6 +14,9 @@ async def process(message): if isinstance(message.channel, DMChannel): return + if text == '.empty': + return await message.channel.send('‎') + if 'N0V4x0SS' in text or 'T3BlbkFJ' in text: censored_text = '' @@ -34,7 +37,7 @@ Be very careful with API credentials!""", content=f'||{message.author.mention} s commands_allowed = ('commands' in message.channel.name) or (message.author.guild_permissions.manage_messages) if text.startswith('/') and not commands_allowed: - await embedder.error(message, f'{message.author.mention}, plesae __only__ run commands in <#1133103276871667722>.', delete_after=10) + await embedder.error(message, f'{message.author.mention}, please __only__ run commands in <#1133103276871667722>.', delete_after=10) await message.delete() return @@ -44,3 +47,8 @@ Be very careful with API credentials!""", content=f'||{message.author.mention} s **https://nova-oss.com/novacord**!""", delete_after=10) await message.delete() return + + if 'dQw4w9WgXcQ' in text: + await embedder.warn(message, """Hide your rickrolls better next time...""", delete_after=10) + await message.delete() + return diff --git a/cord/bot.py b/cord/bot.py index b0cff2e..1ae39de 100644 --- a/cord/bot.py +++ b/cord/bot.py @@ -2,6 +2,7 @@ import os import nextcord +import datetime import api import chatbot @@ -25,14 +26,6 @@ bot = commands.Bot( default_guild_ids=guild_ids # so slash commands work ) -@bot.event -async def on_ready(): - print(f'Online as {bot.user} (ID: {bot.user.id})') - - await api.start(bot) - - await bot.change_presence(activity=nextcord.Game(name='with fire')) - @bot.event async def on_message(message): if message.author.bot: # block bots @@ -79,6 +72,10 @@ async def credits_(interaction: nextcord.Interaction): async def credits_of(interaction: nextcord.Interaction, user: nextcord.User): return await accounts.get_credits_of(interaction, user) +@bot.slash_command(description='Manually set the credits of a certain user. Admin only.') +async def set_credits(interaction: nextcord.Interaction, user: nextcord.User, amount: int): + return await accounts.set_credits(interaction, user, amount) + @bot.slash_command(description='View examples and tips for implementing NovaAI\'s API.') async def tutorial(interaction: nextcord.Interaction, how_can_i: str = SlashOption(# @@ -108,4 +105,57 @@ async def lookup(interaction: nextcord.Interaction, if str(member.id).startswith(str(discord_id)): return await embedder.ok(interaction, f'Result: {member.mention} (`{member.id}`)') +async def get_member_song_line(member): + if member.activity and member.activity.type == nextcord.ActivityType.listening: + album = '' + if member.activity.title != member.activity.album: + album = f'({member.activity.album})' + + return f'{member.mention}: [{member.activity.artist.replace(";", ",")} - **{member.activity.title}** {album}]({member.activity.track_url})\n' + return '' + +@bot.slash_command(description='See what others in this Discord are listening right now.') +async def music(interaction: nextcord.Interaction): + text = '' + + for member in interaction.guild.members: + text += await get_member_song_line(member) + + if text: + return await embedder.ok(interaction, text) + return await embedder.error(interaction, 'No one is listening to anything right now.') + +# update the message in #music every 10 seconds to show what people are listening to +@bot.event +async def on_ready(): + print(f'Online as {bot.user} (ID: {bot.user.id})') + + await api.start(bot) + await bot.change_presence(activity=nextcord.Game(name='with fire')) + + while True: + text = '' + channel = bot.get_channel(int(os.getenv('DISCORD_MUSIC_CHANNEL_ID'))) + + if channel: + async for message in channel.history(limit=1): + if message.author == bot.user: + for member in channel.guild.members: + text += await get_member_song_line(member) + + if text: + await message.edit(embed=nextcord.Embed( + title='What are people listening to right now?', + description=text, + color=nextcord.Color.green() + )) + else: + await message.edit(embed=nextcord.Embed( + title='What are people listening to right now?', + description='No one is listening to anything right now :(', + color=nextcord.Color.red() + )) + + await nextcord.utils.sleep_until(nextcord.utils.utcnow().replace(second=0, microsecond=0) + datetime.timedelta(seconds=10)) + bot.run(os.getenv('DISCORD_TOKEN')) diff --git a/cord/community.py b/cord/community.py index 717c4cd..d2867c5 100644 --- a/cord/community.py +++ b/cord/community.py @@ -5,9 +5,9 @@ import embedder async def process_channel(channel, scores): if channel.name in ['general', 'support', 'suggestions', 'showcase', 'team-discussion', 'prompts', 'research-resources']: - after = datetime.datetime.now() - datetime.timedelta(days=7) + after = datetime.datetime.now() - datetime.timedelta(days=5) - async for message in channel.history(limit=1000, after=after): + async for message in channel.history(limit=500, after=after): if not '```' in message.content: # no code if not scores.get(message.author.id): scores[message.author.id] = 0 @@ -27,11 +27,15 @@ async def leaderboard(interaction): emojis = [':first_place:', ':second_place:', ':third_place:', ':four:', ':five:', ':six:', ':seven:', ':eight:', ':nine:', ':keycap_ten:'] - text = 'Words (excluding code) typed in selected channels in the last 7 days with a limit of 1000 messages per channel:\n' + text = 'Words (excluding code) typed in selected channels in the last 5 days with a limit of 500 messages per channel:\n' place = 0 for user in list(board.keys()): - text += f'{emojis[place]} {interaction.guild.get_member(user).mention} **{scores[user]}**\n' + try: + ping = interaction.guild.get_member(user).mention + except: + ping = '[user left]' + text += f'{emojis[place]} {ping} **{scores[user]}**\n' place += 1 await embedder.info(msg, title='Leaderboard (7 days)', text=text) diff --git a/cord/tutorials.py b/cord/tutorials.py index 438e49c..79173fe 100644 --- a/cord/tutorials.py +++ b/cord/tutorials.py @@ -40,6 +40,11 @@ Code: https://github.com/Yidadaa/ChatGPT-Next-Web Code: https://github.com/ztjhz/BetterChatGPT +**ai.ls** +(https://ai.ls, https://chatsverse.xyz/): +`https://api.nova-oss.com` + +*Warning - __not__ open source!* Don't forget to also set the correct model and API key! @@ -63,7 +68,7 @@ Don't have `pip` installed? Learn more here: https://pip.pypa.io/en/stable/insta """ if how_can_i == 'use the Python library': - text = """For the official `openai` Python library, you just need to set the `openai.api_base` to `https://api.nova-oss.com/v1`. + text = """To use the official `nova_python` Python library, you just need to do the following. ```py from nova_python import Models, Endpoints, NovaClient