async def add_keyword(ctx: commands.Context, args): if not util.user_is_admin(ctx.author.id): return await ctx.send(str(ctx.message.author.mention) + ", you are not authorized.") conn = db_access.create_connection() try: db_access.add_keyword(conn, args) return await ctx.send(str(ctx.message.author.mention) + " added keyword: \"" + args + "\".") except sqlite3.IntegrityError: return await ctx.send(str(ctx.message.author.mention) + ", this keyword already exists")
async def delete_response(ctx: commands.Context, args): if not util.user_is_admin(ctx.author.id): return await ctx.send(str(ctx.message.author.mention) + ", you are not authorized.") conn = db_access.create_connection() if db_access.is_response(args): db_access.delete_response(conn, args) return await ctx.send(str(ctx.message.author.mention) + " removed response: \"" + args + "\".") else: return await ctx.send(str(ctx.message.author.mention) + " \"" + args + "\" is not a response*.")
async def delete_audio_fragment(ctx: commands.Context, args=''): if args is '': return await ctx.send( str(ctx.message.author.mention) + ', please specify a name.') conn = db_access.create_connection() res = db_access.get_fragment_id_by_name(conn, args) os.remove(os.path.join(const.UPLOADED_AUDIO_DIR, str(res[0][0]) + '.wav')) db_access.delete_fragment(conn, res[0][0]) return await ctx.send( str(ctx.message.author.mention) + ' successfully deleted fragment ' + args + '\'.')
async def add_admin(ctx: commands.Context, args): conn = db_access.create_connection() if not util.user_is_admin(ctx.author.id): return await ctx.send(str(ctx.message.author.mention) + ", you are not authorized.") if len(ctx.message.mentions) < 1: return await ctx.send(str(ctx.message.author.mention) + ", please mention at least one user to promote to admin.") for mention in ctx.message.mentions: try: db_access.add_admin(conn, mention.id) await ctx.send(str(ctx.message.author.mention) + ", user " + mention.mention + " is now an admin.") except sqlite3.IntegrityError: return await ctx.send(str(ctx.message.author.mention) + ", user " + mention.mention + " is already an admin.")
async def remove_admin(ctx: commands.Context, args): conn = db_access.create_connection() if not util.user_is_admin(ctx.author.id): return await ctx.send(str(ctx.message.author.mention) + ", you are not authorized.") if len(ctx.message.mentions) < 1: return await ctx.send(str(ctx.message.author.mention) + ", please mention at least one user to demote from admin.") for mention in ctx.message.mentions: if not db_access.is_admin(conn, mention.id): return await ctx.send(str(ctx.message.author.mention) + ", user " + mention.mention + " isn't an admin.") try: db_access.delete_admin(conn, mention.id) await ctx.send(str(ctx.message.author.mention) + ", user " + mention.mention + " is no longer an admin.") except sqlite3.IntegrityError: return await ctx.send(str(ctx.message.author.mention) + ", user " + mention.mention + " isn't an admin.")
async def play_audio_fragment(ctx: commands.Context, args=''): if args is '': return await ctx.send( str(ctx.message.author.mention) + ', please specify a name.') voice_channel: discord.VoiceChannel = ctx.author.voice.channel if voice_channel is not None: conn = db_access.create_connection() fragment_id = db_access.get_fragment_id_by_name(conn, args) vc = await util.join_if_not_in_channel(ctx, voice_channel) audio = discord.FFmpegPCMAudio(executable=const.FFMPG_EXE, source=os.path.join( const.UPLOADED_AUDIO_DIR, str(fragment_id[0][0]) + '.wav')) audio = discord.PCMVolumeTransformer(audio, bot.volume) vc.play(audio)