From 931d4706d20e3a14ac0bc93b8f22917f04506a01 Mon Sep 17 00:00:00 2001 From: AnInternetTroll Date: Wed, 17 Jun 2020 18:50:13 +0200 Subject: De-hardcoded utils, general and logs. The problem left is src. --- .gitignore | 2 +- bot.py | 7 +++++-- cogs/admin.py | 27 +++++++++++++++++++++++++-- cogs/general.py | 2 +- cogs/logs.py | 4 ++-- cogs/utils.py | 17 ++++++++--------- custom_commands.json | 6 ++++-- 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index e63e2cc..e40241a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ __pycache__ -config.py +config.json discord.log api_keys.json .vscode/ diff --git a/bot.py b/bot.py index ccd8d22..533b99d 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,6 @@ import discord import logging import datetime -import config import json extensions = [ @@ -44,6 +43,10 @@ class BedrockBot(commands.Bot): for extension in extensions: self.load_extension(extension) + with open('config.json', 'r') as f: + self.config = json.load(f) + config = self.config + async def on_ready(self): self.uptime = datetime.datetime.utcnow() @@ -78,4 +81,4 @@ class BedrockBot(commands.Bot): return def run(self): - super().run(config.token, reconnect=True) + super().run(self.config["token"], reconnect=True) diff --git a/cogs/admin.py b/cogs/admin.py index d722390..13cb75b 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -134,7 +134,7 @@ class Admin(commands.Cog): members = self.bot.get_user(int(user)) #muted_role = discord.utils.find(ctx.guild.roles, name="Muted") - muted_role = ctx.guild.get_role(707707894694412371) + muted_role = ctx.guild.get_role(self.bot.config[str(ctx.message.guild.id)]["mute_role"]) for member in members: if self.bot.user == member: # what good is a muted bot? embed = discord.Embed(title = "You can't mute me, I'm an almighty bot") @@ -157,7 +157,7 @@ class Admin(commands.Cog): elif type(members)=="str": members = self.bot.get_user(int(user)) - muted_role = ctx.guild.get_role(707707894694412371) + muted_role = ctx.guild.get_role(self.bot.config[str(ctx.message.guild.id)]["mute_role"]) for i in members: await i.remove_roles(muted_role) await ctx.send("{0.mention} has been unmuted by {1.mention}".format(i, ctx.author)) @@ -190,6 +190,29 @@ class Admin(commands.Cog): json.dump(self.bot.blacklist, f, indent=4) await ctx.send(f"{i} has been blacklisted.") + @commands.check(is_mod) + @commands.command() + async def activity(self, ctx,*, activity=None): + if activity: + game = discord.Game(activity) + else: + activity = "Mining away" + game = discord.Game(activity) + await self.bot.change_presence(activity=game) + await ctx.send(f"Activity changed to {activity}") + + @commands.check(is_mod) + @commands.command() + async def setvar(self, ctx, key, *, value): + with open('config.json', 'w') as f: + self.bot.config[str(ctx.message.guild.id)][key] = value + json.dump(self.bot.config, f, indent=4) + + @commands.check(is_mod) + @commands.command() + async def printvar(self, ctx, key): + await ctx.send(self.bot.config[str(ctx.message.guild.id)][key]) + def setup(bot): bot.add_cog(Admin(bot)) diff --git a/cogs/general.py b/cogs/general.py index 2e25410..0847cd4 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -50,7 +50,7 @@ class General(commands.Cog): else: user = self.bot.get_user(int(user)) - coop_role = ctx.guild.get_role(694261282861219952) + coop_role = ctx.guild.get_role(int(self.bot.config[str(ctx.message.guild.id)]["coop_roleID"])) if coop_role in user.roles: await user.remove_roles(coop_role) diff --git a/cogs/logs.py b/cogs/logs.py index d6889eb..8230ccc 100644 --- a/cogs/logs.py +++ b/cogs/logs.py @@ -17,7 +17,7 @@ class Logs(commands.Cog): color = 16777210 else: color = message.author.color - channel = self.bot.get_channel(718187032869994686) + channel = self.bot.get_channel(int(self.bot.config[str(message.guild.id)]["logs_channel"])) embed = discord.Embed( title='Deleted Message', color=color, @@ -34,7 +34,7 @@ class Logs(commands.Cog): async def on_message_edit(self, before, after): if after.guild.id != 574267523869179904: return - channel = self.bot.get_channel(718187032869994686) + channel = self.bot.get_channel(int(self.bot.config[str(before.guild.id)]["logs_channel"])) if before.author.color.value == 0: color = 16777210 else: diff --git a/cogs/utils.py b/cogs/utils.py index c708e54..1deab42 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -25,7 +25,7 @@ def set_viewport_size(driver, width, height): driver.set_window_size(*window_size) async def reportStuff(self, ctx, message): - channel = self.bot.get_channel(715549209998262322) + channel = self.bot.get_channel(self.bot.config[str(ctx.message.guild.id)]["report_channel"]) embed = discord.Embed( title=f"Report from {ctx.message.author}", @@ -48,7 +48,7 @@ class Utils(commands.Cog): @commands.cooldown(1, 25, commands.BucketType.guild) @commands.command() async def findseed(self, ctx): - if ctx.message.channel.id != 684787316489060422: + if ctx.message.channel.id != int(self.bot.config[str(ctx.message.guild.id)]["bot_channel"]): await ctx.message.delete() return @@ -67,13 +67,12 @@ class Utils(commands.Cog): randomness = randint(1, 10) if randomness <= 1: totalEyes += 1 - discname = ctx.message.author.name.replace("@", "@ ") - await ctx.send(f"{discname} -> your seed is a {totalEyes} eye") + await ctx.send(f"{discord.utils.escape_mentions(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): - if ctx.message.channel.id != 684787316489060422: + if ctx.message.channel.id != int(self.bot.config[str(ctx.message.guild.id)]["bot_channel"]): await ctx.message.delete() return else: @@ -82,7 +81,7 @@ class Utils(commands.Cog): @commands.command() async def findsleep(self, ctx): - if ctx.message.channel.id != 684787316489060422: + if ctx.message.channel.id != int(self.bot.config[str(ctx.message.guild.id)]["bot_channel"]): await ctx.message.delete() return @@ -102,7 +101,7 @@ class Utils(commands.Cog): ] # Set up initial message - msg = f"{ctx.message.author.name} -> " + msg = f"{discord.utils.escape_mentions(ctx.message.author.display_name)} -> " # Optional TODO: Create non-normal distribution sleepHrs = randint(0, 24) @@ -125,7 +124,7 @@ class Utils(commands.Cog): @commands.Cog.listener() async def on_message(self, message): - if message.channel.id != 589110766578434078: + if message.channel.id != int(self.bot.config[str(message.guild.id)]["fair_channel"]): return if message.author.bot: return @@ -296,7 +295,7 @@ class Utils(commands.Cog): @commands.command() async def someone(self, ctx): blacklist = [536071288859656193] - if ctx.channel.id != 589110766578434078: + if ctx.channel.id != int(self.bot.config[str(ctx.message.guild.id)]["fair_channel"]): if ctx.author.id == 395872198323077121: await ctx.send("grape is a bitch") elif ctx.author.id == 521153476714299402: diff --git a/custom_commands.json b/custom_commands.json index 6ed04ce..3ea311b 100644 --- a/custom_commands.json +++ b/custom_commands.json @@ -1,5 +1,4 @@ { - "!sr.c": "https://www.speedrun.com/mcbe", "/Troll": "is Super at his job", "/src": "https://www.speedrun.com/mcbe", "!Walk-On-through-the-Wind": "Walk On through the rain", @@ -33,5 +32,8 @@ "!testy": "test", "!toxicitypass": "```TOXICITY PASS\n\nTHE HOLDER OF THIS PASS HAS PERMISSION FROM THE HEAVENS ABOVE TO DO AND SAY WHATEVER THE HELL THEY WANT\nTHEY ARE ALLOWED TO BE AS TOXIC AS THEY WILL WITHOUT REPERCUSSIONS\n\nPASS OWNER: Duck W aka Weexy aka Indy Kambeitz```", "!welcome": "Welcome! <:mango:715738087627685908>", - "!learntoread": "When two players are tied on the leaderboards **ONLY ONE FUCKER WILL BE VISIBLE**" + "!learntoread": "When two players are tied on the leaderboards **ONLY ONE FUCKER WILL BE VISIBLE**", + "!src": "https://www.speedrun.com/mcbe", + "!mobiledupe": "1) place item to dupe in the crafting grid\n2) keep pressed until the green bar thing appears\nclick any \"Impossible\" craft (red ones)\n3)press the item to dupe (that is in your hotbar now -> it should have moved there since you pressed the impossible craft)\n4)your item should be duped", + "!source": "https://github.com/AnInternetTroll/mcbeDiscordBot" } \ No newline at end of file -- cgit v1.2.3