diff options
Diffstat (limited to '')
-rwxr-xr-x | bot.py | 35 | ||||
-rwxr-xr-x | cogs/admin.py | 5 | ||||
-rwxr-xr-x | cogs/help.py | 37 | ||||
-rwxr-xr-x | cogs/src.py | 109 | ||||
-rwxr-xr-x | cogs/utils.py | 125 |
5 files changed, 187 insertions, 124 deletions
@@ -8,13 +8,27 @@ import json extensions = [ "cogs.utils", - "cogs.admin" + "cogs.admin", + "cogs.src", + "cogs.help" ] +def get_prefix(bot, message): + """A callable Prefix for our bot. This could be edited to allow per server prefixes.""" + + prefixes = ['/', '!', 'steve '] + + # Check to see if we are outside of a guild. e.g DM's etc. + #if not message.guild: + # Only allow ? to be used in DMs + # return '?' + + # If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list. + return commands.when_mentioned_or(*prefixes)(bot, message) class BedrockBot(commands.Bot): def __init__(self): - super().__init__(command_prefix=('/', '!')) + super().__init__(command_prefix=get_prefix) self.logger = logging.getLogger('discord') with open('custom_commands.json', 'r') as f: @@ -22,8 +36,6 @@ class BedrockBot(commands.Bot): for extension in extensions: self.load_extension(extension) - - async def on_ready(self): self.uptime = datetime.datetime.utcnow() @@ -37,20 +49,7 @@ class BedrockBot(commands.Bot): if message.author.bot: return - - badWords = ["fair", "f a i r", "ⓕⓐⓘⓡ", "ⓕ ⓐ ⓘ ⓡ"] - try: - if message.channel.id == 589110766578434078: - count = 0 - for word in badWords: - if word in message.content.lower(): - count += 1; - fair = 'Fair '*count - await message.channel.send(fair) - - await self.process_commands(message) - except: - print("shrug") + await self.process_commands(message) command = message.content.split()[0] diff --git a/cogs/admin.py b/cogs/admin.py index 6cbaf52..cf9d8a5 100755 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -10,9 +10,6 @@ class Admin(commands.Cog): async def is_mod(ctx): return ctx.author.guild_permissions.manage_channels - async def is_host(ctx): - return ctx.author.id == 99457716614885376 - @commands.command(aliases=['addcommand', 'newcommand']) @commands.check(is_mod) async def setcommand(self, ctx, command, *, message): @@ -42,7 +39,7 @@ class Admin(commands.Cog): except commands.ExtensionNotFound: await ctx.send(f'The extension {ext} doesn\'t exist.') except commands.ExtensionNotLoaded: - await ctx.send(f'The extension {ext} is not loaded! (use /load)') + await ctx.send(f'The extension {ext} is not loaded! (use {ctx.prefix}load)') except commands.NoEntryPointError: await ctx.send(f'The extension {ext} doesn\'t have an entry point (try adding the setup function) ') except commands.ExtensionFailed: diff --git a/cogs/help.py b/cogs/help.py new file mode 100755 index 0000000..e508650 --- /dev/null +++ b/cogs/help.py @@ -0,0 +1,37 @@ +from discord.ext import commands +from random import randint + +class MyHelpCommand(commands.MinimalHelpCommand): + messages = ["...!", ".party()!", "<PLAYERNAME> IS YOU", + "10 years of Mining and Crafting!", + "12 herbs and spices!", + "12345 is a bad password!", + "150 bpm for 400000 minutes!", + "20 GOTO 10!", + "~~4815162342~~ 5 at most lines of code!", + "90210!", + "A skeleton popped out!", + "Absolutely fixed relatively broken coordinates", + "Absolutely no memes!", + "Afraid of the big, black bat!", + "Age of Wonders is better!", + "Ahhhhhh!"] + aliases_heading = "Other options: " + def get_command_signature(self, command): + return f'``{self.clean_prefix}{command.qualified_name} {command.signature}``' + def get_ending_note(self): + return self.messages[randint(0, len(self.messages)-1)] + +class Help(commands.Cog): + def __init__(self, bot): + self.bot = bot + self._original_help_command = bot.help_command + bot.help_command = MyHelpCommand() + bot.help_command.cog = self + + def cog_unload(self): + self.bot.help_command = self._original_help_command + + +def setup(bot): + bot.add_cog(Help(bot)) diff --git a/cogs/src.py b/cogs/src.py new file mode 100755 index 0000000..708d3fc --- /dev/null +++ b/cogs/src.py @@ -0,0 +1,109 @@ +from discord.ext import commands +from discord.ext import tasks +from discord.utils import get +import discord +import requests +import json +import asyncio +from datetime import timedelta + +async def verifyRole(self, ctx, apiKey): + server = self.bot.get_guild(574267523869179904) + RunneRole = server.get_role(574268937454223361) + WrRole = server.get_role(583622436378116107) + head = { + "X-API-Key":apiKey, + "Accept": "application/json", + "User-Agent":"mcbeDiscordBot/1.0" + } + r = requests.get('https://www.speedrun.com/api/v1/profile', headers=head) + + #print(profile.text) + profile = json.loads(r.text) + pbs = requests.get(profile["data"]["links"][3]["uri"]) + pbs = json.loads(pbs.text) + + for i in pbs["data"]: + if i["place"] == 1: + if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76": + await ctx.send("WR boi") + await server.get_member(ctx.message.author.id).add_roles(WrRole) + print("WR boi") + if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76": + #print(i) + await ctx.send("Runner") + await server.get_member(ctx.message.author.id).add_roles(RunneRole) + #print("minecraft") + + print(r.status_code) + #print(json.dumps(pbs,sort_keys=True, indent=4)) + +async def clear(self): + async for msg in self.bot.get_channel(699713639866957905).history(): + await msg.delete() + + +async def pendingRuns(self, ctx): + head = { + "Accept": "application/json", + "User-Agent":"mcbeDiscordBot/1.0" + } + gameID = 'yd4ovvg1' # ID of Minecraft bedrock + gameID2 = 'v1po7r76' # ID of Category extension + runsRequest = requests.get( + f'https://www.speedrun.com/api/v1/runs?game={gameID}&status=new&max=200&embed=category,players', headers=head) + runs = json.loads(runsRequest.text) + runsRequest2 = requests.get( + f'https://www.speedrun.com/api/v1/runs?game={gameID2}&status=new&max=200&embed=category,players', headers=head) + runs2 = json.loads(runsRequest2.text) + # Use https://www.speedrun.com/api/v1/games?abbreviation=mcbe for ID + + for game in range(2): + for i in range(200): + try: + for key, value in runs['data'][i].items(): + if key == 'weblink': + link = value + if key == 'category': + categoryName = value["data"]["name"] + if key == 'players': + if value["data"][0]['rel'] == 'guest': + player = value["data"][0]['name'] + else: + player = value["data"][0]["names"]["international"] + if key == 'times': + rta = timedelta(seconds=value['realtime_t']) + except Exception as e: + break + if game == 0: + leaderboard = "Minecraft bedrock" + elif game == 1: + leaderboard = "Minecraft Bedrock category extensions" + embed = discord.Embed( + title=leaderboard, url=link, description=f"{categoryName} in `{str(rta).replace('000','')}` by **{player}**", color=16711680+i*60) + await self.bot.get_channel(699713639866957905).send(embed=embed) + runs = runs2 + gameID = gameID2 + +class Src(commands.Cog): + + def __init__(self, bot): + self.bot = bot + + @commands.command(description="Posts all pending runs to #pending-runs") + @commands.guild_only() + async def pending(self, ctx): + await clear(self) + await pendingRuns(self, ctx) + + @commands.command() + async def verify(self, ctx, apiKey=None): + if apiKey == None: + await ctx.send(f"Please try again this command by getting an apiKey from https://www.speedrun.com/api/auth then do `{ctx.prefix}verify <apiKey>` in my DMs or anywhere in this server. \nBe careful who you share this key with. To learn more check out https://github.com/speedruncomorg/api/blob/master/authentication.md") + return + elif ctx.guild != None: + await ctx.message.delete() + await verifyRole(self, ctx, apiKey) + +def setup(bot): + bot.add_cog(Src(bot))
\ No newline at end of file diff --git a/cogs/utils.py b/cogs/utils.py index cd883f8..1555d58 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -1,6 +1,5 @@ from discord.ext import commands from discord.ext import tasks -from discord.utils import get import discord import requests import json @@ -21,106 +20,16 @@ async def translateMsg(text, target="en"): result['detectedSourceLanguage'])) return result; - -async def verifyRole(self, ctx, apiKey): - server = self.bot.get_guild(574267523869179904) - RunneRole = server.get_role(574268937454223361) - WrRole = server.get_role(583622436378116107) - head = { - "X-API-Key":apiKey, - "Accept": "application/json", - "User-Agent":"mcbeDiscordBot/1.0" - } - r = requests.get('https://www.speedrun.com/api/v1/profile', headers=head) - - #print(profile.text) - profile = json.loads(r.text) - pbs = requests.get(profile["data"]["links"][3]["uri"]) - pbs = json.loads(pbs.text) - - for i in pbs["data"]: - if i["place"] == 1: - if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76": - await ctx.send("WR boi") - await server.get_member(ctx.message.author.id).add_roles(WrRole) - print("WR boi") - if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76": - #print(i) - await ctx.send("Runner") - await server.get_member(ctx.message.author.id).add_roles(RunneRole) - #print("minecraft") - - print(r.status_code) - #print(json.dumps(pbs,sort_keys=True, indent=4)) - -async def clear(self): - async for msg in self.bot.get_channel(699713639866957905).history(): - await msg.delete() - - -async def pendingRuns(self, ctx): - head = { - "Accept": "application/json", - "User-Agent":"mcbeDiscordBot/1.0" - } - gameID = 'yd4ovvg1' # ID of Minecraft bedrock - gameID2 = 'v1po7r76' # ID of Category extension - runsRequest = requests.get( - f'https://www.speedrun.com/api/v1/runs?game={gameID}&status=new&max=200&embed=category,players', headers=head) - runs = json.loads(runsRequest.text) - runsRequest2 = requests.get( - f'https://www.speedrun.com/api/v1/runs?game={gameID2}&status=new&max=200&embed=category,players', headers=head) - runs2 = json.loads(runsRequest2.text) - # Use https://www.speedrun.com/api/v1/games?abbreviation=mcbe for ID - - for game in range(2): - for i in range(200): - try: - for key, value in runs['data'][i].items(): - if key == 'weblink': - link = value - if key == 'category': - categoryName = value["data"]["name"] - if key == 'players': - if value["data"][0]['rel'] == 'guest': - player = value["data"][0]['name'] - else: - player = value["data"][0]["names"]["international"] - if key == 'times': - rta = timedelta(seconds=value['realtime_t']) - except Exception as e: - break - if game == 0: - leaderboard = "Minecraft bedrock" - elif game == 1: - leaderboard = "Minecraft Bedrock category extensions" - embed = discord.Embed( - title=leaderboard, url=link, description=f"{categoryName} in `{str(rta).replace('000','')}` by **{player}**", color=16711680+i*60) - await self.bot.get_channel(699713639866957905).send(embed=embed) - runs = runs2 - gameID = gameID2 - class Utils(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.command(description="Pong!", help="Tells the ping of the bot to the discord servers", brief="Tells the ping") async def ping(self, ctx): - # """Shows the Client Latency.""" await ctx.send(f'Pong! {round(self.bot.latency*1000)}ms') - @commands.command() - async def test(self, ctx): - await ctx.send(ctx.message.channel) - - @commands.command() - @commands.guild_only() - async def pending(self, ctx): - await clear(self) - await pendingRuns(self, ctx) - - @commands.command() + @commands.command(help="Translate text in english (using google translate)", brief="Translate to english") async def translate(self, ctx, *, message): response = await translateMsg(message) embed=discord.Embed(title="Translation",description=f"{ctx.message.author.mention} says:", timestamp=ctx.message.created_at, color=0x4d9aff) @@ -135,15 +44,8 @@ class Utils(commands.Cog): embed.add_field(name=f"[{response['detectedSourceLanguage']}] Source:" , value=response['input'], inline=False) embed.add_field(name="Translation", value=response['translatedText'], inline=True) await ctx.send(embed=embed) - - @commands.command() - async def verify(self, ctx, apiKey=None): - if apiKey == None: - await ctx.send("Please try again this command by getting an apiKey from https://www.speedrun.com/api/auth then do `/verify <apiKey>` in my DMs or anywhere in this server. \nBe careful who you share this key with. To learn more check out https://github.com/speedruncomorg/api/blob/master/authentication.md") - elif ctx.guild != None: - await ctx.message.delete() - await verifyRole(self, ctx, apiKey) + @commands.cooldown(1, 25, commands.BucketType.guild) @commands.command() async def findseed(self, ctx): totalEyes = 0 @@ -153,7 +55,26 @@ class Utils(commands.Cog): totalEyes += randomness else: continue - await ctx.send(f"{ctx.message.author.name} -> your seed is a {totalEyes} eye") + await ctx.send(f"{ctx.message.author.display_name} -> your seed is a {totalEyes} eye") + + @findseed.error + async def findseed_handler(self,ctx,error): + if isinstance(error, commands.CommandOnCooldown): + await ctx.send(f"{ctx.message.author.display_name}, you have to wait {round(error.retry_after, 2)} seconds before using this again.") + + @commands.Cog.listener() + async def on_message(self, message): + if message.channel.id != 589110766578434078: + return + if message.author.bot: + return + badWords = ["fair", "f a i r", "ⓕⓐⓘⓡ", "ⓕ ⓐ ⓘ ⓡ"] + count = 0 + for word in badWords: + if word in message.content.lower(): + count += 1; + fair = 'Fair '*count + await message.channel.send(fair) def setup(bot): bot.add_cog(Utils(bot)) |