diff options
-rw-r--r-- | bot.py | 31 | ||||
-rw-r--r-- | bot_utils.py | 12 | ||||
-rw-r--r-- | cogs/fun.py | 19 | ||||
-rw-r--r-- | cogs/modrinth.py | 38 | ||||
-rw-r--r-- | cogs/reddit.py | 19 | ||||
-rw-r--r-- | cogs/utils.py | 22 | ||||
-rw-r--r-- | requirements.txt | 4 |
7 files changed, 60 insertions, 85 deletions
diff --git a/bot.py b/bot.py index 896d1e3..bf73368 100644 --- a/bot.py +++ b/bot.py @@ -1,26 +1,31 @@ -import nextcord -from nextcord.ext import commands import os + +import discord +from discord.ext import commands from dotenv import load_dotenv + import bot_utils -import cogs.fun as F -import cogs.utils as U -import cogs.modrinth as M -import cogs.reddit as R +import cogs.fun as fun +import cogs.reddit as reddit +import cogs.utils as utils +intents = discord.Intents(messages=True, guilds=True, members=True, presences=True, reactions=True) load_dotenv() -bot = commands.Bot(command_prefix="t!", activity=nextcord.Activity(name="for commands", type=nextcord.ActivityType.watching)) -bot.help_command = bot_utils.MyHelpCommand(command_attrs={'hidden':True}) +bot = commands.Bot(command_prefix="t!", + activity=discord.Activity(name="for commands", type=discord.ActivityType.watching)) +bot.help_command = bot_utils.MyHelpCommand(command_attrs={'hidden': True}) @bot.event async def on_ready(): print(f'Logged in as {bot.user.display_name}!') + @bot.event async def on_command_error(ctx, error): await bot_utils.parse_error(ctx, error) - + + @bot.event async def on_message(message): if bot.user.mentioned_in(message): @@ -28,8 +33,8 @@ async def on_message(message): await ctx.reply("<:irritater:882309845427036230>") await bot.process_commands(message) -F.setup(bot) -R.setup(bot) -M.setup(bot) -U.setup(bot) + +fun.setup(bot) +reddit.setup(bot) +utils.setup(bot) bot.run(os.getenv("TOKEN")) diff --git a/bot_utils.py b/bot_utils.py index bed54d7..bf7363c 100644 --- a/bot_utils.py +++ b/bot_utils.py @@ -1,5 +1,6 @@ -import nextcord -from nextcord.ext import commands +import discord +from discord.ext import commands + async def parse_error(ctx, error): if hasattr(ctx.command, 'on_error'): @@ -12,16 +13,17 @@ async def parse_error(ctx, error): if isinstance(error, commands.CommandNotFound): pass else: - embed = nextcord.Embed(title="An error occurred!", color=0xc71a1a) + embed = discord.Embed(title="An error occurred!", color=0xc71a1a) embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/798974923954978817.png?v=1") embed.add_field(name=type(error).__name__, value=error, inline=False) embed.set_footer(text="Tiny Potato Bot") await ctx.send(embed=embed) + class MyHelpCommand(commands.MinimalHelpCommand): async def send_pages(self): destination = self.get_destination() - e = nextcord.Embed(color=0xa37dca, description='') + e = discord.Embed(color=0xa37dca, description='') for page in self.paginator.pages: e.description += page - await destination.send(embed=e) \ No newline at end of file + await destination.send(embed=e) diff --git a/cogs/fun.py b/cogs/fun.py index ef5ed6f..a891ccf 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -1,8 +1,10 @@ -import nextcord -import requests -from nextcord.ext import commands -import urllib.request import random +import urllib.request + +import discord +import requests +from discord.ext import commands + class Fun(commands.Cog): def __init__(self, bot): @@ -24,17 +26,18 @@ class Fun(commands.Cog): else: url = random.choice(["https://fabric-drama.herokuapp.com/txt", "https://mc-drama.herokuapp.com/raw"]) response = urllib.request.urlopen(url).read().decode('utf-8') - embed = nextcord.Embed(color=0xa37dca) + embed = discord.Embed(color=0xa37dca) embed.add_field(name=f"{ctx.author.name} caused drama!", value=response, inline=False) embed.set_footer(text="Tiny Potato Bot v1.0.0") await ctx.send(embed=embed) - @commands.command(name="xkcd", brief="Gets XKCD comics.", help="Gets comics from https://xkcd.com, with the given number.") + @commands.command(name="xkcd", brief="Gets XKCD comics.", + help="Gets comics from https://xkcd.com, with the given number.") async def xkcd(self, ctx, comic=None): if comic is None: try: response = requests.get('https://xkcd.com/info.0.json').json() - embed = nextcord.Embed(title=f"XKCD {response['num']}: {response['safe_title']}", colour=0xa37dca) + embed = discord.Embed(title=f"XKCD {response['num']}: {response['safe_title']}", colour=0xa37dca) embed.set_image(url=response['img']) embed.set_footer(text=response['alt']) await ctx.send(embed=embed) @@ -45,7 +48,7 @@ class Fun(commands.Cog): else: try: response = requests.get(f'https://xkcd.com/{comic}/info.0.json').json() - embed = nextcord.Embed(title=f"XKCD {response['num']}: {response['safe_title']}", colour=0xa37dca) + embed = discord.Embed(title=f"XKCD {response['num']}: {response['safe_title']}", colour=0xa37dca) embed.set_image(url=response['img']) embed.set_footer(text=response['alt']) await ctx.send(embed=embed) diff --git a/cogs/modrinth.py b/cogs/modrinth.py deleted file mode 100644 index 0dddc78..0000000 --- a/cogs/modrinth.py +++ /dev/null @@ -1,38 +0,0 @@ -import nextcord -from nextcord.ext import commands -import requests, datetime, math - -class Modrinth(commands.Cog): - def __init__(self, bot): - self.bot = bot - - @commands.command(name="modrinthmod", brief="Finds a given mod on Modrinth.", help="""Finds a given mod on Modrinth. - You can provide either the slug (`fabric-for-fabric`) or the project ID (`u6KTKg89`). - If you get a JSONDecodeError it's because the mod could not be found!""", aliases=['mrmod', 'modrmod']) - async def modrinth_mod(self, ctx, mod): # 5da426 - response = requests.get(f'https://api.modrinth.com/api/v1/mod/{mod}').json() - embed = nextcord.Embed(title = response['title'], url=f'https://modrinth.com/mod/{mod}', description = response['description'], color = 0x5da426) - embed.set_thumbnail(url = response['icon_url']) - embed.add_field(name='Mod ID', value = response['id'], inline=True) - embed.add_field(name='Categories', value = ', '.join(response['categories']), inline=True) - embed.add_field(name='Downloads', value = response['downloads'], inline=True) - embed.set_footer(text='Tiny Potato Bot') - await ctx.send(embed=embed) - - @commands.command(name="modrinthuser", brief="Finds a given user on Modrinth.", help="""Finds a given user on Modrinth. - You can provide either the username (`redcreeper14385`) or the user ID (`pdimDmDX`). - If you get a JSONDecodeError it's because the user could not be found!""", aliases=['mruser', 'modruser']) - async def modrinth_user(self, ctx, user): # 5da426 - response = requests.get(f'https://api.modrinth.com/api/v1/user/{user}').json() - embed = nextcord.Embed(title=response['username'], url=f'https://modrinth.com/user/{user}', - description=response['bio'], color=0x5da426) - embed.set_thumbnail(url=response['avatar_url']) - embed.add_field(name='User ID', value=response['id'], inline=True) - embed.add_field(name='Registered', value=f"<t:{math.trunc(datetime.datetime.fromisoformat(response['created'].replace('Z', '')).timestamp())}:R>", inline=True) - embed.add_field(name='Role', value=response['role'].capitalize(), inline=True) - embed.set_footer(text='Tiny Potato Bot') - await ctx.send(embed=embed) - - -def setup(bot): - bot.add_cog(Modrinth(bot)) \ No newline at end of file diff --git a/cogs/reddit.py b/cogs/reddit.py index 39c4b38..6ff144f 100644 --- a/cogs/reddit.py +++ b/cogs/reddit.py @@ -1,11 +1,10 @@ -import nextcord -from nextcord.errors import InvalidArgument -from nextcord.ext import commands -from nextcord import ChannelType +import os import random + import asyncpraw -import os from dotenv import load_dotenv +from discord import ChannelType +from discord.ext import commands load_dotenv() reddit = asyncpraw.Reddit( @@ -14,6 +13,7 @@ reddit = asyncpraw.Reddit( user_agent="mounderfod.tpbot:v1.0.0 (by u/mounderfod)" ) + class Reddit(commands.Cog): def __init__(self, bot): self.bot = bot @@ -23,22 +23,23 @@ class Reddit(commands.Cog): """, aliases=['redd', 'r']) async def redditimg(self, ctx, sub): sub = await reddit.subreddit(sub) - img_posts = [i async for i in sub.hot(limit=100) if not i.is_self and i.domain != "v.redd.it" ] + img_posts = [i async for i in sub.hot(limit=100) if not i.is_self and i.domain != "v.redd.it"] if len(img_posts) == 0: - await ctx.reply("This subreddit has no image posts!", mention_author = False) + await ctx.reply("This subreddit has no image posts!", mention_author=False) else: post = random.choice(img_posts) nsfw = post.over_18 if nsfw and ctx.channel.type == ChannelType.text and not ctx.channel.is_nsfw(): - await ctx.reply("The selected post is NSFW, and this is not an NSFW channel.", mention_author = False) + await ctx.reply("The selected post is NSFW, and this is not an NSFW channel.", mention_author=False) else: for i in get_image_embed(post): await ctx.send(i) - + def setup(bot): bot.add_cog(Reddit(bot)) + def get_image_embed(post): result = ["Post by " + post.author.name + ": " + post.title] if hasattr(post, "is_gallery"): diff --git a/cogs/utils.py b/cogs/utils.py index 4657ad2..a574249 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -1,5 +1,6 @@ -import nextcord -from nextcord.ext import commands +import discord +from discord.ext import commands + class Utils(commands.Cog): def __init__(self, bot): @@ -7,15 +8,16 @@ class Utils(commands.Cog): @commands.command(name="about", brief="Gives information about the bot.", help="Gives information about the bot.") async def about(self, ctx): - embed = nextcord.Embed(title="Tiny Potato Bot", - description="The creator of Tiny Potato Bot is mounderfod (aka redcreeper14385), find him here:", + embed = discord.Embed(title="Tiny Potato Bot", + description="The creator of Tiny Potato Bot is mounderfod (aka CraftVoltage), find him here:", color=0xa37dca) - embed.add_field(name="GitHub", value="https://github.com/redcreeper14385", inline=False) - embed.add_field(name="Twitch", value="https://twitch.tv/mounderfod", inline=False) - embed.add_field(name="Discord", value="mounderfod#4179", inline=False) - embed.add_field(name="Reddit", value="https://www.reddit.com/user/mounderfod", inline=False) - embed.set_footer(text="Tiny Potato Bot v1.0.0") + embed.add_field(name="GitHub", value="https://github.com/mounderfod", inline=False) + embed.add_field(name="Twitch", value="https://twitch.tv/mounderfod_", inline=False) + embed.add_field(name="Discord", value="mounderfod#5949", inline=False) + embed.add_field(name="Reddit", value="https://www.reddit.com/user/craftvoltage", inline=False) + embed.set_footer(text="Tiny Potato Bot v2.0.0") await ctx.send(embed=embed) + def setup(bot): - bot.add_cog(Utils(bot)) \ No newline at end of file + bot.add_cog(Utils(bot)) diff --git a/requirements.txt b/requirements.txt index 15a5568..7a5b1be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ python-dotenv == 0.19.0 requests ~= 2.26.0 -nextcord~=2.0.0a3 -asyncpraw ~= 7.4.0 +discord.py~=1.7.0 +asyncpraw ~= 7.5.0 |