def create_poll(self, event, question: str): responses = {} for letter in self.LETTERS: event.msg.reply( "Response {}: Send 'exit' to post, 'cancel' to cancel the poll" .format(letter)) msg = self.get_msg(event) if msg is None: return if msg.content == 'exit': break if msg.content == 'cancel': return responses[letter] = msg.content if self.poll_msg: self.reset_channel() embed = MessageEmbed() embed.title = "New poll question!" embed.color = 0x6832E3 embed.timestamp = datetime.utcnow().isoformat() embed.description = "\n".join( [question + "\n"] + [l + " **" + q + "**" for l, q in responses.items()]) self.sub_role.update(mentionable=True) sleep(.5) poll_msg = self.poll_channel.send_message(self.sub_role.mention, embed=embed) self.sub_role.update(mentionable=False) self.poll_msg = poll_msg self.poll_msg.pin() for emoji in responses: sleep(.5) self.poll_msg.add_reaction(emoji)
def start(cls, event, game_channel, players, game_type): guild = Guild.using_id(event.guild.id) game = cls.create( guild_id=event.guild.id, game_channel=game_channel, players=[x.id for x in players], type_=game_type, ) if guild.log_channel and guild.logs_enabled: embed = MessageEmbed() embed.title = 'Game Ended!' player_list = [] for x in players: player_list.append('`*` {x} | `{x.id}`'.format(x=x)) game_info = [ '**Game**: {}'.format(num_str.get(game_type)), '**Channel**: <#{channel}> (`{channel}`)'.format( channel=game.game_channel), '**ID**: {}'.format(game.id) ] embed.add_field(name='Players »', value='\n'.join(player_list)) embed.add_field(name='Game Info »', value='\n'.join(game_info)) embed.set_footer(text='Started By {}'.format(event.author), icon_url=event.author.get_avatar_url()) embed.timestamp = datetime.utcnow().isoformat() event.guild.channels.get(guild.log_channel)\ .send_message(embed=embed) return game
def jeopardy_command(self, event, args): self.log.info('{} executed !jeopardy with args: {}'.format( event.author, args)) if not args.random: return jservice_base_url = 'http://jservice.io/{}' jservice_random = '/api/random' jeopardy_response = requests.get( jservice_base_url.format(jservice_random)).json()[0] from pprint import pprint pprint(jeopardy_response) jeopardy_q = jeopardy_response['question'].replace('&', 'and') jeopardy_a = self.clean_html(jeopardy_response['answer']) jeopardy_id = jeopardy_response['id'] jeopardy_amount = '${}'.format(jeopardy_response['value']) jeopardy_category = jeopardy_response['category']['title'] jeopardy_q = '\n'.join([ ' '.join(jeopardy_q.split()[s:s + 6]) for s in range(0, len(jeopardy_q.split()), 6) ]) self.log.info('amount: {}'.format(jeopardy_amount)) img2txt_url = 'http://api.img4me.com/?text={}&font=impact&size=35&fcolor={}&bcolor=060CE9' question_color = 'FFFFFF' amount_color = 'D49516' question_value = requests.get( img2txt_url.format(jeopardy_q, question_color)).text amount_value = requests.get( img2txt_url.format(jeopardy_amount, amount_color)).text embed = MessageEmbed() embed.set_author( name='Jeopardy!', url='http://jservice.io/', icon_url= 'http://jservice.io/assets/trebek-503ecf6eafde622b2c3e2dfebb13cc30.png' ) embed.title = 'Category: {}'.format(jeopardy_category) embed.timestamp = pendulum.now().in_tz('America/New_York').isoformat() embed.set_thumbnail(url=amount_value) embed.set_image(url=question_value) embed.set_footer(text='Powered by jservice.io') embed.color = '13931798' # dark yellow (hex: #D49516) event.msg.reply(embed=embed)
def on_tags_info(self, event, name): try: tag = Tag.select(Tag, User).join( User, on=(User.user_id == Tag.author_id).alias('author') ).where( (Tag.guild_id == event.guild.id) & (Tag.name == S(name)) ).get() except Tag.DoesNotExist: raise CommandFail('no tag by that name exists') embed = MessageEmbed() embed.title = tag.name embed.description = tag.content embed.add_field(name='Author', value=unicode(tag.author), inline=True) embed.add_field(name='Times Used', value=str(tag.times_used), inline=True) embed.timestamp = tag.created_at.isoformat() event.msg.reply(embed=embed)
def get_embed(self, star, msg, config): # Create the 'header' (non-embed) text stars = ':star:' if len(star.stars) > 1: if len(star.stars) >= config.star_color_max: stars = ':star2:' stars = stars + ' {}'.format(len(star.stars)) content = '**{}** <#{}> ({})'.format(stars, msg.channel_id, msg.id) # Generate embed section embed = MessageEmbed() embed.description = '{}'.format(msg.content) if msg.attachments: attach = list(msg.attachments.values())[0] if attach.url.lower().endswith( ('png', 'jpeg', 'jpg', 'gif', 'webp')): embed.set_image(url=attach.url) if msg.embeds: if msg.embeds[0].image.url: embed.set_image(url=msg.embeds[0].image.url) elif msg.embeds[0].thumbnail.url: embed.set_image(url=msg.embeds[0].thumbnail.url) author = msg.guild.get_member(msg.author) if author: embed.set_author(name=author, icon_url=author.user.avatar_url) else: embed.set_author(name=msg.author, icon_url=msg.author.avatar_url) embed.timestamp = msg.timestamp.isoformat() embed.color = config.get_color(len(star.stars)) row = ActionRow() row.add_component(label='Jump to Message', type=ComponentTypes.BUTTON, style=ButtonStyles.LINK, url='https://discord.com/channels/{}/{}/{}'.format( msg.guild.id, msg.channel_id, msg.id)) return content, embed, row
def on_info_command(self, event): """Displays some info about the bot, or me!""" infoEmbed = MessageEmbed() github = "https://github.com/One-Nub/Who-Am-I" myPfpImg = "https://i.lensdump.com/i/WDsOXb.png" botPfpImg = "https://i.lensdump.com/i/WDs4G5.png" botInvite = ("https://discordapp.com/api/oauth2/authorize?client_id=" + "592796597209792542&permissions=380096&scope=bot") infoEmbed.title = "Welcome to **Who Am I**!" infoEmbed.url = github infoEmbed.color = 0x8DD0E1 infoEmbed.description = ( "Hey there! This bot was created for the June 2019 " + "Discord Hackathon!") infoEmbed.set_thumbnail(url=botPfpImg) infoEmbed.set_author(name="Nub#8399", icon_url=myPfpImg) infoEmbed.timestamp = datetime.utcnow().isoformat() infoEmbed.add_field( name="What is/was this Hackathon?", value= "This was a week where developers, such as myself, would create" " either a bot of some sort, " "or something creative (art, music, etc...), " "and we would then submit our creations by the end of the week!", inline=False) infoEmbed.add_field( name="So what does this bot do?", value= "This bot is meant to make it easier to learn about people and share" "info about yourself!" "\nThis is done by letting users give info to the bot" "& then displaying that info with a simple command!", inline=False) infoEmbed.add_field(name="View my github here!", value=github, inline=False) infoEmbed.add_field(name="Invite me here!", value="[Invite me!]({})".format(botInvite), inline=False) event.msg.reply(embed=infoEmbed)
def end_connect_four(var): game_data = var game = Games.with_id(game_data.id) game.winner = game_data.winner game.turn_count = game_data.turns game.ended = True game.save() guild = Guild.using_id(game_data.guild.id) board = game_data.game_board.get_final() for x in range(4): board = board[:board.rfind('\n')] if guild.log_channel and guild.logs_enabled: embed = MessageEmbed() embed.title = 'Game Ended!' player_list = [] players = [game_data.guild.members.get(x) for x in game_data.players] for x in players: player_list.append('`*` {x} | `{x.id}`'.format(x=x)) game_info = [ '**Game**: {}'.format(num_str.get(1)), '**Total Turns**: {}'.format(game.turn_count), '**ID**: {}'.format(game.id) ] embed.add_field(name='Players »', value='\n'.join(player_list)) embed.add_field(name='Game Info »', value='\n'.join(game_info)) embed.set_footer(text='The Winner Is {}'.format( game_data.guild.members.get(game_data.winner).user), icon_url=game_data.guild.members.get( game_data.winner).user.get_avatar_url()) embed.timestamp = datetime.utcnow().isoformat() game_data.guild.channels.get(guild.log_channel)\ .send_message(embed=embed) bembed = MessageEmbed() bembed.description = board bembed.title = 'Game Board' game_data.guild.channels.get(guild.log_channel)\ .send_message(embed=bembed)
def update_hint(self, hint): if hint.claimed_datetime: embed = MessageEmbed() embed.color = 0xff0000 embed.timestamp = hint.claimed_datetime.isoformat() embed.author.name = 'Claimed by {}'.format(hint.claimer) if hint.claimer in self.avatars: embed.author.icon_url = self.avatars[hint.claimer] debug = 'claimed by {}'.format(hint.claimer) else: embed = EmptyEmbed() debug = 'unclaimed' if hint.discord_id and self.client is not None: try: self.client.channels_messages_modify(self.HINT_CHANNEL, hint.discord_id, embed=embed) except Exception: dispatch_general_alert( 'Discord API failure: modify\n{}'.format( traceback.format_exc())) else: message = hint.discord_message() if self.client is None: logger.info('Hint, {}: {}\n{}'.format(debug, hint, message)) return try: discord_id = self.client.channels_messages_create( self.HINT_CHANNEL, message, embed=embed).id except Exception: dispatch_general_alert( 'Discord API failure: create\n{}'.format( traceback.format_exc())) return hint.discord_id = discord_id hint.save(update_fields=('discord_id', ))