diff --git a/All-In-One-bot/bot.py b/All-In-One-bot/bot.py index f776cea34ce6bf2250ccfde290b0baa6bc49e1e6..99f67bd1628600d037043cdc054f53955ff6074b 100644 --- a/All-In-One-bot/bot.py +++ b/All-In-One-bot/bot.py @@ -39,8 +39,6 @@ initial_extensions = ( 'cogs.meta', 'cogs.misc', 'cogs.mod', - 'cogs.ombi', - 'cogs.plex', 'cogs.polls', 'cogs.music' ) diff --git a/All-In-One-bot/cogs/admin.py b/All-In-One-bot/cogs/admin.py index 4e4202d49033d1fc90b1e44b14f25d8bba36012a..7740199a441610629176861cd79398ee761a6cf5 100644 --- a/All-In-One-bot/cogs/admin.py +++ b/All-In-One-bot/cogs/admin.py @@ -30,6 +30,7 @@ class Admin: async def __local_check(self, ctx): return await self.bot.is_owner(ctx.author) + def get_syntax_error(self, e): if e.text is None: return f'```py\n{e.__class__.__name__}: {e}\n```' diff --git a/All-In-One-bot/cogs/buttons.py b/All-In-One-bot/cogs/buttons.py index db3ba4b45c3004a7b346f8448e12817864cd37f8..58122b5b9a0798019f249a03a2eb284f46bf2710 100644 --- a/All-In-One-bot/cogs/buttons.py +++ b/All-In-One-bot/cogs/buttons.py @@ -121,12 +121,6 @@ class Buttons: """depress""" await ctx.send('*depressed*') - @commands.command() - async def love(self, ctx): - """What is love?""" - action = random.choice([ctx.send('https://www.youtube.com/watch?v=HEXWRTEbj1I'), await ctx.invoke(self.g, query='define: love')]) - await action - @commands.command(hidden=True) async def bored(self, ctx): """boredom looms""" diff --git a/All-In-One-bot/cogs/config.py b/All-In-One-bot/cogs/config.py index 28e2d570f42ca51ae1329685cabb5428b54f448c..bee1a7f4bdeab53cc8f60381e7398f89b98d5dbb 100644 --- a/All-In-One-bot/cogs/config.py +++ b/All-In-One-bot/cogs/config.py @@ -31,6 +31,7 @@ class LazyEntity: self._cache = resolved.mention return self._cache + class ChannelOrMember(commands.Converter): async def convert(self, ctx, argument): try: @@ -38,6 +39,7 @@ class ChannelOrMember(commands.Converter): except commands.BadArgument: return await commands.MemberConverter().convert(ctx, argument) + class Plonks(db.Table): id = db.PrimaryKeyColumn() guild_id = db.Column(db.Integer(big=True), index=True) @@ -45,6 +47,7 @@ class Plonks(db.Table): # this can either be a channel_id or an author_id entity_id = db.Column(db.Integer(big=True), index=True, unique=True) + class CommandConfig(db.Table, table_name='command_config'): id = db.PrimaryKeyColumn() @@ -61,6 +64,7 @@ class CommandConfig(db.Table, table_name='command_config'): sql = "CREATE UNIQUE INDEX IF NOT EXISTS command_config_uniq_idx ON command_config (channel_id, name, whitelist);" return statement + '\n' + sql + class CommandName(commands.Converter): async def convert(self, ctx, argument): lowered = argument.lower() @@ -76,9 +80,11 @@ class CommandName(commands.Converter): return lowered + class ResolvedCommandPermissions: class _Entry: __slots__ = ('allow', 'deny') + def __init__(self): self.allow = set() self.deny = set() @@ -112,7 +118,7 @@ class ResolvedCommandPermissions: command_names = self._split(ctx.command.qualified_name) - guild = self._lookup[None] # no special channel_id + guild = self._lookup[None] # no special channel_id channel = self._lookup[ctx.channel.id] blocked = None @@ -144,6 +150,7 @@ class ResolvedCommandPermissions: return blocked + class Config: """Handles the bot's configuration system. @@ -188,7 +195,7 @@ class Config: # check if we're plonked is_plonked = await self.is_plonked(ctx.guild.id, ctx.author.id, channel_id=ctx.channel.id, - connection=ctx.db, check_bypass=False) + connection=ctx.db, check_bypass=False) return not is_plonked @@ -421,5 +428,6 @@ class Config: """Disables a command for this server.""" await ctx.invoke(self.server_disable, command=command) + def setup(bot): bot.add_cog(Config(bot)) diff --git a/All-In-One-bot/cogs/general.py b/All-In-One-bot/cogs/general.py index 9c76697a8ce41db5f1dd9a1fdbfd52329152ec04..76e48fc6786cf2e225c41db602fe99013a387119 100644 --- a/All-In-One-bot/cogs/general.py +++ b/All-In-One-bot/cogs/general.py @@ -1,9 +1,5 @@ -import os -import sys - import discord from discord.ext import commands -from discord.ext.commands.converter import MemberConverter class General: @@ -12,39 +8,7 @@ class General: @commands.command(name="ping", brief="Ping pong") async def ping(self, ctx): - await ctx.say("Pong!") - - @commands.group(name="faq", brief="Frequently Asked Questions", pass_context=True) - async def frequently_asked_questions(self, ctx): - if ctx.invoked_subcommand is None: - embed = discord.Embed(title="Frequently Asked Questions") - embed.add_field(name="Want to know about the requests system?", value="Just execute this command with with `requests` after it.", inline=False) - await ctx.say(embed=embed) - pass - - @frequently_asked_questions.command() - async def requests(self, ctx): - embed=discord.Embed(title="Plex Media Request System FAQ", color=0xdc1111) - embed.add_field(name="1. Where can I find it?", value="It's located at: https://home.samip.fi/pmrs/", inline=False) - embed.add_field(name="2. How do I log-on?", value="You login with your plex.tv credentials.\nThe admin wont see it as it's securely checked against plex.tv API.", inline=False) - embed.set_footer(text="Generated by samip5's code.") - await ctx.say(embed=embed) - - @commands.group(name='dm-faq', pass_context=True) - async def direct_message_frequently_asked_questions(self, ctx): - if ctx.invoked_subcommand is None: - message = "This is not supposed to be called without anything after it. Please fix your command and try again." - await ctx.say(message) - pass - - @direct_message_frequently_asked_questions.command(pass_context=True) - async def requests(self, ctx, member: discord.Member): - footer = f"Called by {ctx.message.author}" - embed = discord.Embed(title="Plex Media Request System FAQ", color=0xdc1111) - embed.add_field(name="1. Where can I find it?", value="It's located at: https://home.samip.fi/pmrs/", inline=False) - embed.add_field(name="2. How do I log-on?", value="You login with your plex.tv credentials.\nThe admin wont see it as it's securely checked against plex.tv API.", inline=False) - embed.set_footer(text=footer) - await ctx.messegable.send(member, embed=embed) + await ctx.send("Pong!") def setup(bot): diff --git a/All-In-One-bot/cogs/misc.py b/All-In-One-bot/cogs/misc.py index bbb94285e12d85b13e4b14000604f5f463eb2d3f..c55e730fc6db76e5d16872548c7f42931c50ca8b 100644 --- a/All-In-One-bot/cogs/misc.py +++ b/All-In-One-bot/cogs/misc.py @@ -31,7 +31,7 @@ class Misc: f = discord.Embed(color=random.randint(1, 255 ** 3 - 1)) f.set_image(url=thumb_url) f.set_footer(text="Powered by Giphy.") - await ctx.say(embed=f) + await ctx.send(embed=f) @commands.command(name='cat', description="Gives you a random cat picture", brief="Returns random image of a cat") async def randomcat(self, ctx): @@ -42,7 +42,7 @@ class Misc: e.set_image(url=ret['file']) e.set_author(name="Random.cat", url='https://random.cat/') e.set_footer(text="Powered by random.cat") - await ctx.say(embed=e) + await ctx.send(embed=e) async def on_member_update(self, before, after): if before.nick != after.nick: diff --git a/All-In-One-bot/cogs/mod.py b/All-In-One-bot/cogs/mod.py index 06f75c9455c32286a5ea463adc181522a009ecd7..938671799daf8feddf02e3d13137e65d297e94f5 100644 --- a/All-In-One-bot/cogs/mod.py +++ b/All-In-One-bot/cogs/mod.py @@ -14,12 +14,14 @@ import logging log = logging.getLogger(__name__) + ## Misc utilities class Arguments(argparse.ArgumentParser): def error(self, message): raise RuntimeError(message) + class RaidMode(enum.Enum): off = 0 on = 1 @@ -28,6 +30,7 @@ class RaidMode(enum.Enum): def __str__(self): return self.name + ## Tables class GuildConfig(db.Table, table_name='guild_mod_config'): @@ -37,6 +40,7 @@ class GuildConfig(db.Table, table_name='guild_mod_config'): mention_count = db.Column(db.Integer(small=True)) safe_mention_channel_ids = db.Column(db.Array(db.Integer(big=True))) + ## Configuration class ModConfig: @@ -60,6 +64,7 @@ class ModConfig: guild = self.bot.get_guild(self.id) return guild and guild.get_channel(self.broadcast_channel_id) + ## Converters @@ -145,7 +150,7 @@ class Mod: if config.raid_mode != RaidMode.strict.value: return - delta = (member.joined_at - member.created_at).total_seconds() // 60 + delta = (member.joined_at - member.created_at).total_seconds() // 60 # they must have created their account at most 30 minutes before they joined. if delta > 30: @@ -176,7 +181,8 @@ class Mod: try: await member.kick(reason='Strict raid mode') except discord.HTTPException: - log.info(f'[Raid Mode] Failed to kick {member} (ID: {member.id}) from server {member.guild} via strict mode.') + log.info( + f'[Raid Mode] Failed to kick {member} (ID: {member.id}) from server {member.guild} via strict mode.') else: log.info(f'[Raid Mode] Kicked {member} (ID: {member.id}) from server {member.guild} via strict mode.') self._recently_kicked[guild.id].add(member.id) @@ -263,13 +269,13 @@ class Mod: # Do the broadcasted message to the channel if was_kicked: title = 'Member Re-Joined' - colour = 0xdd5f53 # red + colour = 0xdd5f53 # red else: title = 'Member Joined' - colour = 0x53dda4 # green + colour = 0x53dda4 # green if created < 30: - colour = 0xdda453 # yellow + colour = 0xdda453 # yellow e = discord.Embed(title=title, colour=colour) e.timestamp = now @@ -433,10 +439,10 @@ class Mod: if msg.author == ctx.me: await msg.delete() count += 1 - return { 'Bot': count } + return {'Bot': count} async def _complex_cleanup_strategy(self, ctx, search): - prefixes = tuple(self.bot.get_guild_prefixes(ctx.guild)) # thanks startswith + prefixes = tuple(self.bot.get_guild_prefixes(ctx.guild)) # thanks startswith def check(m): return m.author == ctx.me or m.content.startswith(prefixes) @@ -607,7 +613,8 @@ class Mod: return await ctx.send('Sorry, this functionality is currently unavailable. Try again later?') await ctx.guild.ban(discord.Object(id=member), reason=reason) - timer = await reminder.create_timer(duration.dt, 'tempban', ctx.guild.id, ctx.author.id, member, connection=ctx.db) + timer = await reminder.create_timer(duration.dt, 'tempban', ctx.guild.id, ctx.author.id, member, + connection=ctx.db) await ctx.send(f'Banned ID {member} for {time.human_timedelta(duration.dt)}.') async def on_tempban_timer_complete(self, timer): @@ -636,7 +643,7 @@ class Mod: @commands.group(invoke_without_command=True) @commands.guild_only() @checks.has_permissions(ban_members=True) - async def mentionspam(self, ctx, count: int=None): + async def mentionspam(self, ctx, count: int = None): """Enables auto-banning accounts that spam mentions. If a message contains `count` or more mentions then the @@ -832,6 +839,7 @@ class Mod: async def _emoji(self, ctx, search=100): """Removes all messages containing custom emoji.""" custom_emoji = re.compile(r'<:(\w+):(\d+)>') + def predicate(m): return custom_emoji.search(m.content) @@ -952,9 +960,9 @@ class Mod: return not r return r - args.search = max(0, min(2000, args.search)) # clamp from 0-2000 + args.search = max(0, min(2000, args.search)) # clamp from 0-2000 await self.do_removal(ctx, args.search, predicate, before=args.before, after=args.after) def setup(bot): - bot.add_cog(Mod(bot)) \ No newline at end of file + bot.add_cog(Mod(bot)) diff --git a/All-In-One-bot/cogs/plex.py b/All-In-One-bot/cogs/plex.py index e2230237538a913ec54581a23ab509d0db660fce..9cc5e0fca605c2c97c9723af646eaf41faedf46d 100644 --- a/All-In-One-bot/cogs/plex.py +++ b/All-In-One-bot/cogs/plex.py @@ -30,11 +30,9 @@ class Plex: player = session.players[0].platform duration = session.duration duration_millis = session.duration - # duration_seconds = int(duration_millis / 1000) % 60 duration_minutes = int(duration_millis / (1000 * 60)) % 60 duration_hours = hours = (duration_millis / (1000 * 60 * 60)) % 24 if duration_hours >= 1: - # total_duration = ("%d Hours and %d Minutes" % (duration_hours, duration_minutes)) total_duration = f'{duration_hours} Hours and {duration_minutes} Minutes' else: # total_duration = ("%d Minutes" % duration_minutes) @@ -44,14 +42,9 @@ class Plex: view_offset_minutes = int(view_offset_millis / (1000 * 60)) % 60 view_offset_hours = int(view_offset_millis / (1000 * 60 * 60)) % 24 if view_offset_hours >= 1: - # offset = ("%d Hours and %d Minutes" % (view_offset_hours, view_offset_minutes)) offset = f'{view_offset_hours} Hours and {view_offset_minutes} Minutes' else: - # offset = ("%d Minutes" % view_offset_minutes) offset = f'{view_offset_minutes} Minutes' - # print("ms: %d" % (view_offset)) - # print("Minutes: %d" % (view_offset_minutes)) - # print("Hours: %d" % (view_offset_hours)) percentage = round(view_offset / duration * 100) username = session.usernames[0] if session.type == 'episode': @@ -88,8 +81,6 @@ class Plex: async def search_plex_though_tautulli(self, ctx, input): tautulli_url = "{tautulli_base_url}api/v2?apikey={api_key}&cmd=search&query={string}".format( tautulli_base_url=TAUTULLI_BASE_URL, api_key=TAUTULLI_API_KEY, string=input) - # tautulli_query = "{string}" - # print (f'Plex Extension: Tautulli API called with query string of' tautulli_query) async with aiohttp.ClientSession() as ses: async with ses.get(tautulli_url) as resp: a = await resp.json() diff --git a/Music-bot/bot.py b/Music-bot/bot.py index 690da9ab99c52a3a84fb4c408872b530ea87e65b..591532db2e96003bc816af27369f2cbf1b5accaf 100644 --- a/Music-bot/bot.py +++ b/Music-bot/bot.py @@ -8,8 +8,8 @@ from discord.ext import commands def get_prefix(bot, message): - prefixes = ['?'] - return commands.when_mentioned_or(*prefixes)(bot, message) + prefixes = ['?'] + return commands.when_mentioned_or(*prefixes)(bot, message) initial_extensions = ['cogs.meta', 'cogs.owner', 'cogs.music', 'cogs.error_handler', 'jishaku'] @@ -24,20 +24,20 @@ production_token = config.get('token', 'prod') @bot.event async def on_ready(): - bot.uptime = datetime.datetime.utcnow() - print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nAPI Version: {discord.__version__}\n') + bot.uptime = datetime.datetime.utcnow() + print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nAPI Version: {discord.__version__}\n') + print(f'Server count: {len(bot.guilds)}') if __name__ == '__main__': - if any('debug' in arg.lower() for arg in sys.argv): - bot.command_prefix = '$' - for extension in initial_extensions: - try: - bot.load_extension(extension) - except: - print(f'Failed to load extension {extension}.', file=sys.stderr) - traceback.print_exc() - # bot.run(dev_token) - + if any('debug' in arg.lower() for arg in sys.argv): + bot.command_prefix = '$' + for extension in initial_extensions: + try: + bot.load_extension(extension) + except: + print(f'Failed to load extension {extension}.', file=sys.stderr) + traceback.print_exc() +# bot.run(dev_token) bot.run(production_token) diff --git a/Music-bot/cogs/error_handler.py b/Music-bot/cogs/error_handler.py index 9e2065c5d857628b6cc196e693037af48a3151d0..47c9056c6b5669fd9c19155f217c63460b075b52 100644 --- a/Music-bot/cogs/error_handler.py +++ b/Music-bot/cogs/error_handler.py @@ -56,4 +56,4 @@ class CommandErrorHandler: def setup(bot): - bot.add_cog(CommandErrorHandler(bot)) \ No newline at end of file + bot.add_cog(CommandErrorHandler(bot)) diff --git a/Music-bot/cogs/meta.py b/Music-bot/cogs/meta.py index 23f555ad2bda7e17e8ce2b7b9791c4644ef007cc..3b738426a5fd51da6001e3851b22455819fec318 100644 --- a/Music-bot/cogs/meta.py +++ b/Music-bot/cogs/meta.py @@ -2,6 +2,7 @@ import discord import datetime import asyncio import os +import socket from discord.ext import commands @@ -95,8 +96,7 @@ class Meta: result.append(f'- Bot ID: {self.bot.user.name} (Discord ID: {self.bot.user.id})') result.append('- Created on July 3rd, 2018') result.append('- Library: discord.py (Python)') - result.append('- Running proudly on Google Cloud Platform') - result.append("- Source: https://0xacab.org/samip537/discord-bots-private (Private)") + result.append(f'- System hostname: {socket.gethostname()}') # changes = os.popen( # r'git show -s HEAD~3..HEAD --format="[%h](https://github.com/samip5/Discord-Bots/commit/%H) %s (%cr)"').read().strip() # result.append('- Changes: {}'.format(changes))