async def remove_banned(self, ctx, target): if ctx.author.id in ADMINS: logger.log_and_print( "control", f"Removing {target} from banned channels list") temp = [] with open("data/banned_channels.csv", mode="r", newline="") as file: try: temp = list(csv.reader(file, delimiter=",")) except: pass with open("data/banned_channels.csv", mode="w", newline="") as file: writer = csv.writer(file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL) for line in temp: try: if line[0] != target: try: writer.writerow(line) except: pass except: pass temp = [] await ctx.send("Done!")
async def say(self, ctx, channel, *, target=None): if str(ctx.author.id) in ADMINS: if target == None: await ctx.send("Need a message") else: channel = self.bot.get_channel(int(channel)) logger.log_and_print( "control", f"Sent message {str(target)} to channel {str(channel)}") await channel.send(target)
async def update_banned(self, ctx): if ctx.author.id in ADMINS: BANNED_CHANNELS = [] with open("data/banned_channels.csv", mode="r", newline="") as file: reader = csv.reader(file, delimiter=",") for line in reader: BANNED_CHANNELS.append(int(line[0])) logger.log_and_print("control", "Updated internal banned channels list") await ctx.send("Done!")
async def add_banned(self, ctx, target, *, comment=None): if ctx.author.id in ADMINS: logger.log_and_print( "control", f"Adding {target} to banned channels list with comment {comment}" ) with open("data/banned_channels.csv", mode="a", newline="") as file: writer = csv.writer(file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow([target, str(" # " + str(comment))]) await ctx.send("Done!")
async def _pin_message(self, ctx, guild_id, pin_channel): message_id = ctx.id vid_mode = False # Checks if the message has already been pinned. Due to how Discord deals with messages, # we can ignore messages older than the current bot instance if str(message_id) in self.pins_store: return # Generate base embed posted_message = discord.Embed(description=str(ctx.content), colour=0xcb410b) posted_message.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url) # Manage attachments if ctx.attachments != []: vid_mode = ctx.attachments[0].url.split( ".")[-1] in repo.config["video_formats"] if (not vid_mode): posted_message.set_image(url=ctx.attachments[0].url) else: posted_message.description += f" [{(ctx.attachments[0].url).split('/')[-1]}]" posted_message.set_footer( text=(ctx.created_at + timedelta(hours=10)).strftime("%d %b %Y at %I:%M%p AEST")) await self.bot.get_channel(pin_channel).send( f"Message pinned from {ctx.channel.mention}. context: https://www.discordapp.com/channels/{str(guild_id)}/{str(ctx.channel.id)}/{str(message_id)}", embed=posted_message) if (vid_mode): await self.bot.get_channel(pin_channel).send(ctx.attachments[0].url ) self.pins_store.append(str(message_id)) logger.log_and_print( "pins", f"Pinned message: '{str(ctx.content)}' by {ctx.author.display_name}. Attachments: {ctx.attachments == []}" )
async def on_ready(self): if not hasattr(self.bot, 'uptime'): self.bot.uptime = datetime.datetime.now() await self.bot.change_presence(status=discord.Status.online, activity=MESSAGE) logger.log_and_print( "events", f"ORB Core {VERSION_DATA['Colour']} {VERSION_DATA['Version']} Build {VERSION_DATA['Build']}" ) logger.log_and_print("events", '------------------------------------------') logger.log_and_print("events", 'Bot is online and connected to Discord.') if len(self.bot.guilds) == 1: logger.log_and_print( "events", f'Currently connected to {len(self.bot.guilds)} server.') else: logger.log_and_print( "events", f'Currently connected to {len(self.bot.guilds)} servers.') logger.log_and_print("events", '------------------------------------------') logger.log_and_print("events", f'Bot Name: {self.bot.user.name}') logger.log_and_print("events", f'Bot ID: {str(self.bot.user.id)}') logger.log_and_print("events", '') logger.log_and_print("events", f'Discord.py Version: {discord.__version__}') logger.log_and_print("events", f'Python Version: {sys.version[:5]}') logger.log_and_print("events", '') logger.log_and_print( "events", f'orb.py Version: {str(repo.VERSION_DATA["Version"])}') logger.log_and_print("events", '------------------------------------------')
# Verifies if the command is allowed to be executed # This is a utility function and shouldn't be called on it's own (hence the lack of .command decorator) # Not async because a). Incredibly low complexity (aka fast) # b). This is a priority to execute # c). Nothing would be awaited in here so an async function would work the same as a regular def allowed_channel(ctx): if ctx in BANNED_CHANNELS: return False else: return True # Connects to Cloud Firestore logger.log_and_print("control", "Verifiying with server") os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = repo.config['keys'][ 'firestore_key_path'] db = firestore.Client() logger.log_and_print("control", "Connected to Google Cloud Firestore") BANNED_CHANNELS = [] ADMINS = repo.config['controllers'] with open("data/banned_channels.csv", mode="r") as file: reader = csv.reader(file, delimiter=",") for line in reader: try: BANNED_CHANNELS.append(int(line[0])) except: