async def formatting(self, ctx): msgs = await lang.get_lang(ctx) e = lang.EmbedBuilder(msgs['notifs']['notif_variables']) e.set_footer(icon_url=ctx.author.avatar_url or ctx.author.default_avatar_url, text=str(ctx.author)) await ctx.send(embed=e)
async def listen(self, ctx, *, url: str): """Listen to the specified Twitch user in the current voice channel.""" msgs = await lang.get_lang(ctx) url = "https://www.twitch.tv/" + url.split('/')[-1] if (not hasattr(ctx.author, "voice")) or ctx.author.voice is None: return await ctx.send(msgs['audio']['author_not_in_voice_channel']) voice_channel = ctx.author.voice.channel prem_check = requests.get(f"https://api.twitchbot.io/premium/{ctx.author.id}", headers={"X-Auth-Key": settings.DashboardKey}) if prem_check.json().get('premium') != True or prem_check.status_code != 200: r = requests.get(f"https://dash.twitchbot.io/api/users/{ctx.author.id}/votes", headers={"X-Auth-Key": settings.DashboardKey}) if r.status_code != 200 or r.json()['active'] == False: # Fallback in case the dashboard failed r = http.BotLists.DBLRequest(f"/bots/375805687529209857/check?userId={ctx.author.id}") if r.status_code == 200 and not r.json()['voted'] == 1: return await ctx.send(embed=lang.EmbedBuilder(msgs['audio']['need_upvote_to_continue'])) m = await ctx.send(msgs['audio']['please_wait']) try: try: channel = await voice_channel.connect() except discord.ClientException: session = ctx.message.guild.voice_client await session.disconnect() await asyncio.sleep(2) channel = await voice_channel.connect() except Exception as ex: return await ctx.send(f"A {type(ex).__name__} occurred: {ex}") try: r = http.TwitchAPIRequest("https://api.twitch.tv/helix/streams?user_login="******"twitch.tv/")[1]) if len(r.json()["data"]) < 1: return await m.edit(content=msgs['audio']['user_does_not_exist_or_not_streaming']) r = r.json()["data"][0] r2 = http.TwitchAPIRequest("https://api.twitch.tv/helix/users?login="******"twitch.tv/")[1]) if len(r2.json()["data"]) < 1: return await m.edit(content=msgs['audio']['user_does_not_exist_or_not_streaming']) r2 = r2.json()["data"][0] e = discord.Embed(color=0x6441A4, title=msgs['audio']['now_playing']['title'].format(channel=voice_channel.name), description=msgs['audio']['now_playing']['description'].format(title=r['title'], viewer_count=r['viewer_count'])) e.set_author(name=r2['display_name'], url=url, icon_url=r2['profile_image_url']) e.set_image(url=r['thumbnail_url'].format(width=1920, height=1080) + f"?{secrets.token_urlsafe(5)}") e.set_footer(icon_url=ctx.author.avatar_url or ctx.author.default_avatar_url, text=f"{ctx.author} - {msgs['audio']['now_playing']['footer']}") player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) channel.play(player, after=lambda e: logging.error("{}: {}".format(type(e).__name__, e)) if e else None) self.bot.active_vc[ctx.message.guild.id] = e await m.edit(content=None, embed=e) except youtube_dl.DownloadError: await ctx.send(msgs['audio']['user_does_not_exist_or_not_streaming']) except TimeoutError: await ctx.send(msgs['audio']['connection_timeout']) except discord.ClientException as ex: await ctx.send(f"{type(ex).__name__}: {ex}") #await ctx.send("I'm already in a voice channel. Please stop the existing stream and then start it in the new channel.") except: raise
async def on_message(message): try: datadog.statsd.increment('bot.messages_received') if message.author.bot: return elif message.content.lower().startswith(tuple(bot.command_prefix)): if message.author.id in settings.BannedUsers: return await message.channel.send( "You have been banned from using TwitchBot.") if not bot.is_ready(): msgs = await lang.get_lang( lang.FakeCtxObject(bot, message.author)) return await message.channel.send( msgs['errors']['not_started']) if message.guild: logging.info( "{0.author} {0.author.id} in {0.guild.name} {0.guild.id}: {0.clean_content}" .format(message)) else: logging.info( "{0.author} {0.author.id} in DM: {0.clean_content}". format(message)) if message.content.lower() in tuple( map(lambda t: t + "help", bot.command_prefix)): # === Send help command === # msgs = await lang.get_lang( lang.FakeCtxObject(bot, message.author)) if not settings.UseBetaBot: datadog.statsd.increment('bot.commands_run', tags=["command:help"]) return await message.channel.send( embed=lang.EmbedBuilder(msgs['help_command'])) else: splitter = message.content.split(' && ') for s in splitter: message.content = s await bot.process_commands(message) elif message.guild is None: return except: await message.channel.send("An unexpected error occurred:\n" + traceback.format_exc())
async def notif(self, ctx): if ctx.invoked_subcommand is None: msgs = await lang.get_lang(ctx) await ctx.send( embed=lang.EmbedBuilder(msgs['notifs']['command_usage']))
async def cmds(self, ctx): msgs = await lang.get_lang(ctx) await ctx.send(embed=lang.EmbedBuilder(msgs['commands_list']))