async def leave(self, ctx): if basic.get_value(self.bot.playing, ctx.guild.id) == 2: return await ctx.send( "Error: Already trying to leave your voice channel!") if ctx.channel.id != settings.get(ctx.guild, "channel"): return await ctx.send( "Error: Wrong channel, do -channel get the channel that has been setup." ) if basic.get_value(self.bot.playing, ctx.guild.id) == 3: return await ctx.send("Error: Trying to join a voice channel!") elif ctx.author.voice is None: return await ctx.send( "Error: You need to be in a voice channel to make me leave!") elif ctx.guild.voice_client is None: return await ctx.send( "Error: How do I leave a voice channel if I am not in one?") elif ctx.author.voice.channel != ctx.guild.voice_client.channel: return await ctx.send( "Error: You need to be in the same voice channel as me to make me leave!" ) self.bot.playing[ctx.guild.id] = 2 await ctx.guild.voice_client.disconnect(force=True) self.bot.playing[ctx.guild.id] = 0 await ctx.send("Left voice channel!")
def get(guild, user): all_nicknames = settings_class.get(guild, "nicknames") nickname = get_value(all_nicknames, str(user.id), default_value=user.display_name) return nickname
async def on_voice_state_update(self, member, before, after): guild = member.guild vc = guild.voice_client playing = basic.get_value(self.bot.playing, guild.id) if member.id == self.bot.user.id: return # someone other than bot left vc elif not (before.channel and not after.channel): return # user left voice channel elif not vc: return # bot in a voice channel elif len([member for member in vc.channel.members if not member.bot]) != 0: return # bot is only one left elif playing not in (0, 1): return # bot not already joining/leaving a voice channel else: self.bot.playing[guild.id] = 2 await vc.disconnect(force=True) self.bot.playing[guild.id] = 0
async def join(self, ctx): if basic.get_value(self.bot.playing, ctx.guild.id) == 3: return await ctx.send( "Error: Already trying to join your voice channel!") if ctx.channel.id != settings.get(ctx.guild, "channel"): return await ctx.send( "Error: Wrong channel, do -channel get the channel that has been setup." ) if ctx.author.voice is None: return await ctx.send( "Error: You need to be in a voice channel to make me join your voice channel!" ) channel = ctx.author.voice.channel permissions = channel.permissions_for(ctx.guild.me) if not permissions.view_channel: return await ctx.send( "Error: Missing Permission to view your voice channel!") if not permissions.speak or not permissions.use_voice_activation: return await ctx.send("Error: I do not have permssion to speak!") if ctx.guild.voice_client is not None and ctx.guild.voice_client == channel: return await ctx.send("Error: I am already in your voice channel!") if ctx.guild.voice_client is not None and ctx.guild.voice_client != channel: return await ctx.send("Error: I am already in a voice channel!") self.bot.playing[ctx.guild.id] = 3 await channel.connect() self.bot.playing[ctx.guild.id] = 0 await ctx.send("Joined your voice channel!")
def get(user): return get_value(setlangs, str(user.id), default_value="en-us")
def get(guild, setting): return get_value(settings, str(guild.id), setting, default_value=default_settings[setting])
async def on_message(self, message): if message.channel.id == 749971061843558440 and message.embeds and str( message.author) == "GitHub#0000": print("Message is from a github webhook") if " new commit" in message.embeds[0].title: print("Message is a commit") update_for_main = message.embeds[0].title.startswith( "[Discord-TTS-Bot:master]" ) and self.bot.user.id == 513423712582762502 update_for_dev = message.embeds[0].title.startswith( "[Discord-TTS-Bot:dev]" ) and self.bot.user.id == 698218518335848538 cog_update = message.embeds[0].title.startswith( "[Common-Cogs:master]") print(update_for_main, update_for_dev, cog_update, "\n===============================================") if update_for_main or update_for_dev: await self.bot.channels['logs'].send( f"Detected new bot commit! Pulling changes") call(['git', 'pull']) print("===============================================") await self.bot.channels['logs'].send("Restarting bot...") await self.end(message) elif cog_update: await self.bot.channels['logs'].send( f"Detected new cog commit! Pulling changes") call([ 'git', 'submodule', 'update', '--recursive', '--remote' ]) print("===============================================") await self.bot.channels['logs'].send("Reloading cog...") try: self.bot.reload_extension("cogs.common_user") self.bot.reload_extension("cogs.common_owner") self.bot.reload_extension("cogs.common_trusted") except Exception as e: await self.bot.channels['logs'].send( f'**`ERROR:`** {type(e).__name__} - {e}') else: await self.bot.channels['logs'].send('**`SUCCESS`**') elif message.guild is not None: saythis = message.clean_content.lower() # Get settings autojoin = settings.get(message.guild, "auto_join") bot_ignore = settings.get(message.guild, "bot_ignore") starts_with_tts = saythis.startswith("-tts") # if author is a bot and bot ignore is on if bot_ignore and message.author.bot: return # if author is not a bot, and is not in a voice channel, and doesn't start with -tts if not message.author.bot and message.author.voice is None and starts_with_tts is False: return # if bot **not** in voice channel and autojoin **is off**, return if message.guild.voice_client is None and autojoin is False: return # Check if a setup channel if message.channel.id != settings.get(message.guild, "channel"): return # If message is **not** empty **or** there is an attachment if int(len(saythis)) != 0 or message.attachments: # Ignore messages starting with - that are probably commands (also advertised as a feature when it is wrong lol) if saythis.startswith(BOT_PREFIX) is False or starts_with_tts: # This line :( | if autojoin is True **or** message starts with -tts **or** author in same voice channel as bot if autojoin or starts_with_tts or message.author.bot or message.author.voice.channel == message.guild.voice_client.channel: #Auto Join if message.guild.voice_client is None and autojoin and basic.get_value( self.bot.playing, message.guild.id) in (0, 1): try: channel = message.author.voice.channel except AttributeError: return self.bot.playing[message.guild.id] = 3 await channel.connect() self.bot.playing[message.guild.id] = 0 # Sometimes bot.guilds is wrong, because intents if message.guild.id not in self.bot.queue: self.bot.queue[message.guild.id] = dict() # Emoji filter saythis = basic.emojitoword(saythis) # Acronyms and removing -tts saythis = f" {saythis} " acronyms = { "@": " at ", "irl": "in real life", "gtg": " got to go ", "iirc": "if I recall correctly", "™️": "tm", "rn": "right now", "wdym": "what do you mean", "imo": "in my opinion", } if starts_with_tts: acronyms["-tts"] = "" for toreplace, replacewith in acronyms.items(): saythis = saythis.replace(f" {toreplace} ", f" {replacewith} ") saythis = saythis[1:-1] if saythis == "?": saythis = "what" # Regex replacements regex_replacements = { r"\|\|.*?\|\|": ". spoiler avoided.", r"```.*?```": ". code block.", r"`.*?`": ". code snippet.", } for regex, replacewith in regex_replacements.items(): saythis = re.sub(regex, replacewith, saythis, flags=re.DOTALL) # Url filter changed = False for word in saythis.split(" "): if word.startswith("https://") or word.startswith( "http://") or word.startswith("www."): saythis = saythis.replace(word, "") changed = True if changed: saythis += ". This message contained a link" # Toggleable X said and attachment detection if settings.get(message.guild, "xsaid"): said_name = settings.nickname.get( message.guild, message.author) format = basic.exts_to_format(message.attachments) if message.attachments: if len(saythis) == 0: saythis = f"{said_name} sent {format}." else: saythis = f"{said_name} sent {format} and said {saythis}" else: saythis = f"{said_name} said: {saythis}" if basic.remove_chars(saythis, " ", "?", ".", ")", "'", '"') == "": return # Read language file lang = setlangs.get(message.author) temp_store_for_mp3 = BytesIO() try: gTTS.gTTS( text=saythis, lang=lang).write_to_fp(temp_store_for_mp3) except AssertionError: return except (gTTS.tts.gTTSError, ValueError): return await message.channel.send( f"Ah! gTTS couldn't process {message.jump_url} for some reason, please try again later." ) # Discard if over 30 seconds temp_store_for_mp3.seek(0) if not (int(MP3(temp_store_for_mp3).info.length) >= 30): self.bot.queue[message.guild.id][ message.id] = temp_store_for_mp3 del temp_store_for_mp3 # Queue, please don't touch this, it works somehow while self.bot.playing[message.guild.id] != 0: if self.bot.playing[message.guild.id] == 2: return await asyncio.sleep(0.5) self.bot.playing[message.guild.id] = 1 while self.bot.queue[message.guild.id] != dict(): # Sort Queue self.bot.queue[message.guild.id] = basic.sort_dict( self.bot.queue[message.guild.id]) # Select first in queue message_id_to_read = next( iter(self.bot.queue[message.guild.id])) selected = self.bot.queue[ message.guild.id][message_id_to_read] selected.seek(0) # Play selected audio vc = message.guild.voice_client if vc is not None: try: vc.play( FFmpegPCMAudio( selected.read(), pipe=True, options='-loglevel "quiet"')) except discord.errors.ClientException: pass # sliences desyncs between discord.py and discord, implement actual fix soon! while vc.is_playing(): await asyncio.sleep(0.5) # Delete said message from queue if message_id_to_read in self.bot.queue[ message.guild.id]: del self.bot.queue[ message.guild.id][message_id_to_read] else: # If not in a voice channel anymore, clear the queue self.bot.queue[message.guild.id] = dict() # Queue should be empty now, let next on_message though self.bot.playing[message.guild.id] = 0 elif message.author.bot is False: pins = await message.author.pins() if [ True for pinned_message in pins if pinned_message.embeds and pinned_message.embeds[0].title == f"Welcome to {self.bot.user.name} Support DMs!" ]: if "https://discord.gg/" in message.content.lower(): await message.author.send( f"Join https://discord.gg/zWPWwQC and look in <#694127922801410119> to invite {self.bot.user.mention}!" ) elif not blocked_users.check(message.author): files = [ await attachment.to_file() for attachment in message.attachments ] webhook = await basic.ensure_webhook( self.bot.channels["dm_logs"], name="TTS-DM-LOGS") await webhook.send(message.content, username=str(message.author), avatar_url=message.author.avatar_url, files=files) else: embed_message = cleandoc(""" **All messages after this will be sent to a private channel on the support server (-invite) where we can assist you.** Please keep in mind that we aren't always online and get a lot of messages, so if you don't get a response within a day, repeat your message. There are some basic rules if you want to get help though: `1.` Ask your question, don't just ask for help `2.` Don't spam, troll, or send random stuff (including server invites) `3.` Many questions are answered in `-help`, try that first (also the prefix is `-`) """) embed = discord.Embed( title=f"Welcome to {self.bot.user.name} Support DMs!", description=embed_message) dm_message = await message.author.send( "Please do not unpin this notice, if it is unpinned you will get the welcome message again!", embed=embed) await self.bot.channels["logs"].send( f"{str(message.author)} just got the 'Welcome to Support DMs' message" ) await dm_message.pin()