async def announce_stream_end(self): """Edit stream announcement in Discord""" try: game_name = api_fetch('game') stream_title = api_fetch('title') vod_url = api_fetch('vod_replay', channel='maerictv').split('?')[0] embed = discord.Embed( title=f"**MaericTV's {game_name} stream has ended!**", url=vod_url, description=stream_title, color=0x463aff) embed.add_field(name="But there's always the vod:", value=vod_url) embed.set_image(url=self.splash_url_over) stream_channel = self.get_channel( int(environ['DISCORD_STREAMING_CHANNEL'])) messages = await stream_channel.history(limit=20).flatten() old_message = discord.utils.get( messages, id=value_set.BOT_OPTIONS.get('stream_message')) await old_message.edit(embed=embed) except Exception: print(f"!! hybrid_bot::announce_stream_end: {format_exc()}") finally: if value_set.BOT_OPTIONS['player_enabled']: # Stop player value_set.BOT_OPTIONS['discord_voice_channel'] = environ[ 'DISCORD_VOICE_CHANNEL'] value_set.BOT_OPTIONS['player_enabled'] = False await self.disconnect_all_voice() await self.dj_send( "_Stream went offline. Player auto-disabled!_") value_set.BOT_OPTIONS['stream_message'] = None value_set.BOT_OPTIONS['stream_online'] = False save_dict(value_set.BOT_OPTIONS, 'bot_options')
def exec_shoutout(msg): """Do a shoutout for the provided user""" if msg.mentions: last_played = simple_tools.api_fetch('game', msg.mentions[0]) return f"Check out {msg.mentions[0]}'s channel, and give them a follow! They were last seen " \ f"playing {last_played} at https://www.twitch.tv/{msg.mentions[0]}" elif msg.args: last_played = simple_tools.api_fetch('game', msg.args[0]) return f"Check out {msg.args[0]}'s channel, and give them a follow! They were last seen " \ f"playing {last_played} at https://www.twitch.tv/{msg.args[0]}" return f'I didn\'t see any mentions, so I\'ll just shoutout myself! @{environ["BOT_NAME"]} razCool'
def exec_uptime(msg): """Get stream uptime from Twitch""" content = simple_tools.api_fetch('uptime') if 'offline' not in content: return f"{environ['TWITCH_CHANNEL']} has been live for: {content}" else: return f"{environ['TWITCH_CHANNEL']} is not live razBot"
def get_data(*args, region=None): """Fetch data from GW2 api""" if region is None: region = 'eu' if 'EU' in api_fetch('title') else 'na' token = region_key.get(region) url = f"https://api.guildwars2.com/v2/{'/'.join(args)}" headers = {"Authorization": f"Bearer {token}"} data = get(url, headers=headers).json() return data
async def announce_stream_start(self): """Announce stream to Discord""" try: game_name = api_fetch('game') stream_title = api_fetch('title') embed = discord.Embed( title=f"**MaericTV just went live with {game_name}!**", url="https://www.twitch.tv/maerictv", description=stream_title, color=0x463aff) embed.add_field(name='Come join us!', value="https://www.twitch.tv/maerictv") embed.set_image(url=self.splash_url_start) stream_channel = self.get_channel( int(environ['DISCORD_STREAMING_CHANNEL'])) stream_message = await stream_channel.send(content="@here", embed=embed) value_set.BOT_OPTIONS['stream_message'] = stream_message.id except Exception: print(f"!! hybrid_bot::announce_stream_start: {format_exc()}") finally: value_set.BOT_OPTIONS['stream_online'] = True save_dict(value_set.BOT_OPTIONS, 'bot_options')
def get_cauliflower_score(region='na'): cf_total = 0 print(f">> Loading item data from {obj_path}/item_data.json") with open(f"{obj_path}/item_data.json", 'r') as f: character_item_data = json.loads(f.read()) play_region = 'eu' if 'EU' in api_fetch('title') else 'na' if play_region == region: # Update current character this_character = get_character() char_name_enc = this_character.replace(' ', '%20') upper_inventory = get_data('characters', char_name_enc, 'inventory') bags = upper_inventory.get('bags') items = flatten(i.get('inventory') for i in bags if i) character_item_data[region][this_character] = items # Count Cauliflower from all characters for character in character_item_data[region]: items = character_item_data[region][character] cf_count = sum(i.get('count') for i in items if i and i.get('id') == 12532) cf_total += cf_count return cf_total
def stream_is_online(self): """Checks whether the stream is online""" uptime_report = api_fetch('uptime') return "minutes" in uptime_report or "seconds" in uptime_report
def exec_title(msg): """Get the current stream title from Twitch""" return "The stream title is: {}".format(simple_tools.api_fetch('title'))
def exec_game(msg): """Get the current game from Twitch""" content = simple_tools.api_fetch('game') return "{0} is currently playing: {1}".format(environ['TWITCH_CHANNEL'], content)
def exec_howlong(msg): """Get invoking user's follow time""" content = simple_tools.api_fetch('followage', msg.user) return "{0} has been following for: {1}".format(msg.display_name, content)