class Tags(commands.Cog): def __init__(self, bot, firebase_ref): self.bot = bot self.firebase_ref = firebase_ref @cog_ext.cog_subcommand( base="tag", description="Create a tag.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option( name="name", description="Name of the tag, followed by the content of the tag.", option_type=3, required=True ) ] ) @commands.guild_only() async def create(self, ctx: SlashContext, name: str): await ctx.defer() if len(split_request := name.split()) > 1: tag_name = split_request[0] tag_content = name[len(tag_name) + 1:] if tag_name not in self.firebase_ref.child('tags').get(): self.firebase_ref.child('tags/{0}'.format(tag_name)).set(tag_content) await ctx.send(embed=hkd.create_embed(title='Successfully created tag - {0}'.format(tag_name))) else: await ctx.send(embed=hkd.create_embed(title='That tag already exists. Please choose a different tag name.', colour=Colour.red())) return await ctx.send(embed=hkd.create_embed(description="Couldn't create tag.", colour=Colour.red()))
class Info(commands.Cog): def __init__(self, bot): self.bot = bot @cog_ext.cog_slash( description="Show details of the specified member, or your own details if not specified.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option( name="member", description="The member to show details for.", option_type=6, required=False ) ] ) @commands.guild_only() async def userinfo(self, ctx: SlashContext, member: Member = None): await ctx.defer() user = member or ctx.author embed_fields = [] embed_fields.append(('Name', '{0}'.format(user.display_name))) embed_fields.append(('ID', '{0}'.format(user.id))) embed_fields.append(('Joined Server', '{0:%Y}-{0:%m}-{0:%d} {0:%H}:{0:%M}:{0:%S} UTC'.format(user.joined_at))) embed_fields.append(('Account Created', '{0:%Y}-{0:%m}-{0:%d} {0:%H}:{0:%M}:{0:%S} UTC'.format(user.created_at))) embed_fields.append(('Roles', '{0}'.format(', '.join([r.name for r in user.roles[1:]]) if user.roles[1:] else 'None'))) embed_fields.append(('Avatar', '{0}'.format('<{0}>'.format(user.avatar_url) if user.avatar_url else 'None'))) await ctx.send(content='**User Information for {0.mention}**'.format(user), embed=hkd.create_embed(fields=embed_fields, inline=True)) @cog_ext.cog_slash( description="Show server information.", guild_ids=hkd.get_all_guild_ids(), ) @commands.guild_only() async def serverinfo(self, ctx: SlashContext): await ctx.defer() guild = ctx.guild embed_fields = [] embed_fields.append(('{0}'.format(guild.name), '(ID: {0})'.format(guild.id))) embed_fields.append(('Owner', '{0} (ID: {1})'.format(guild.owner, guild.owner.id))) embed_fields.append(('Members', '{0}'.format(guild.member_count))) embed_fields.append(('Channels', '{0} text, {1} voice'.format(len(guild.text_channels), len(guild.voice_channels)))) embed_fields.append(('Roles', '{0}'.format(len(guild.roles)))) embed_fields.append(('Created On', '{0:%Y}-{0:%m}-{0:%d} {0:%H}:{0:%M}:{0:%S} UTC'.format(guild.created_at))) embed_fields.append(('Region', '{0}'.format(guild.region))) embed_fields.append(('Icon', '{0}'.format('<{0}>'.format(guild.icon_url) if guild.icon_url else 'None'))) await ctx.send(content='**Server Information**', embed=hkd.create_embed(fields=embed_fields, inline=True))
class Help(commands.Cog): def __init__(self, bot): self.bot = bot @cog_ext.cog_subcommand(base="help", description="See detailed help for role commands.", guild_ids=hkd.get_all_guild_ids()) @commands.guild_only() async def roles(self, ctx: SlashContext): await ctx.defer() description = 'Users can have any of the 7 WUG member roles. Use the /oshihen command to get the role you want.\n\n' for oshi in hkd.WUG_ROLE_IDS: description += '**/oshihen** {0} for {1.mention}\n'.format( oshi.title(), hkd.get_wug_role(ctx.guild, oshi)) description += "\nNote that using **/oshihen** will remove all of your existing member roles. To get an extra role without removing existing ones, use **/oshimashi** *member* instead. To get all 7 roles, use **/hakooshi**. Use **/kamioshi** *member* to specify which member you want to set as your highest role (you will get that member's colour).\n\n" description += 'Use **/oshi-count** to show the number of members with each WUG member role, or **/kamioshi-count** to show the number of members with each WUG member role as their highest role.\n' await ctx.send(content='**Commands for Roles**', embed=hkd.create_embed(description=description)) @cog_ext.cog_subcommand( base="help", description="See detailed help for event commands.", guild_ids=hkd.get_all_guild_ids()) async def events(self, ctx: SlashContext): await ctx.defer() embed_fields = [] embed_fields.append(( '/events *date*', 'Get information for events involving WUG members on the specified date, e.g. **/events** apr 1. If *date* not specified, finds events happening today.' )) embed_fields.append(( '/eventsin *month* *member*', 'Get information for events involving WUG members for the specified month and member, e.g. **/eventsin** April Mayushii. If *member* not specified, searches for Wake, Up Girls! related events instead. Searches events from this month onwards only.' )) await ctx.send(content='**Commands for Searching Events**', embed=hkd.create_embed(fields=embed_fields))
class Oshi(commands.Cog): def __init__(self, bot): self.bot = bot @cog_ext.cog_slash( description="Change to a different WUG member role.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option(name="member", description="The member that you want the role of.", option_type=3, required=True, choices=hkd.get_member_choices()) ]) @commands.guild_only() async def oshihen(self, ctx: SlashContext, member: str = ''): await ctx.defer() if not (role := hkd.get_wug_role(ctx.guild, member)): await ctx.send(embed=hkd.create_embed( description= "Couldn't find that role. Use **/help roles** to show additional help on how to get roles.", colour=Colour.red())) return roles_to_remove = [] for existing_role in ctx.author.roles: if existing_role.id in hkd.WUG_ROLE_IDS.values( ) or existing_role.id in hkd.WUG_KAMIOSHI_ROLE_IDS.values(): roles_to_remove.append(existing_role) if len(roles_to_remove) == 1 and roles_to_remove[0].name == role.name: await ctx.send(embed=hkd.create_embed( description= 'Hello {0.author.mention}, you already have that role.'.format( ctx), colour=Colour.red())) elif roles_to_remove: await ctx.author.remove_roles(*roles_to_remove) await asyncio.sleep(0.5) await ctx.author.add_roles(role) await ctx.send(embed=hkd.create_embed( description= 'Hello {0.author.mention}, you have oshihened to the **{1}** role {2.mention}.' .format(ctx, member.title(), role), colour=role.colour))
class Pics(commands.Cog): def __init__(self, bot, twitter_api, insta_api): self.bot = bot self.twitter_api = twitter_api self.insta_api = insta_api @cog_ext.cog_slash(description="Get images from the specified tweet.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option(name="url", description="URL of the tweet.", option_type=3, required=True) ]) async def tweetpics(self, ctx: SlashContext, url: str): await ctx.defer() status_id = hkd.get_tweet_id_from_url(url) status = self.twitter_api.GetStatus(status_id=status_id, include_my_retweet=False) tweet = status.AsDict() if not (media := tweet.get('media', [])): return pics = [p.get('media_url_https', '') for p in media] await hkd.send_content_with_delay(ctx, pics)
required=True) ]) async def tweetpics(self, ctx: SlashContext, url: str): await ctx.defer() status_id = hkd.get_tweet_id_from_url(url) status = self.twitter_api.GetStatus(status_id=status_id, include_my_retweet=False) tweet = status.AsDict() if not (media := tweet.get('media', [])): return pics = [p.get('media_url_https', '') for p in media] await hkd.send_content_with_delay(ctx, pics) @cog_ext.cog_slash( description="Get images from the specified Instagram post.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option(name="url", description="URL of the Instagram post.", option_type=3, required=True) ]) @commands.cooldown(1, 10, BucketType.guild) async def instapics(self, ctx: SlashContext, url: str): await ctx.defer() if not ((shortcode := hkd.get_id_from_url(url, '/p/', '/')) or (shortcode := hkd.get_id_from_url(url, '/reel/', '/'))): return images, videos = [], [] post = Post.from_shortcode(self.insta_api.context, shortcode) if post.typename == 'GraphSidecar':
class Events(commands.Cog): def __init__(self, bot): self.bot = bot @cog_ext.cog_slash( description= "Show events involving WUG members on the specified date, or for today if not specified.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option(name="date", description="Date to search for events.", option_type=3, required=False) ]) @commands.guild_only() async def events(self, ctx: SlashContext, date: str = ''): await ctx.defer() event_urls = [] current_time = datetime.now(timezone('Japan')) search_date = parser.parse(date) if date else current_time if current_time.month > search_date.month or current_time.month == search_date.month and current_time.day > search_date.day: search_year = current_time.year + 1 else: search_year = current_time.year first = True for _ in range(3): with suppress(Exception): soup = hkd.get_html_from_url( 'https://www.eventernote.com/events/month/{0}-{1}-{2}/1?limit=1000' .format(search_year, search_date.month, search_date.day)) result = soup.find_all( attrs={'class': ['date', 'event', 'actor', 'note_count']}) for event in [ result[i:i + 4] for i in range(0, len(result), 4) ]: info = event[1].find_all('a') event_time = event[1].find('span') if (event_url := info[0]['href']) not in event_urls: performers = [ p.contents[0] for p in event[2].find_all('a') ] wug_performers = [ p for p in performers if p in hkd.WUG_MEMBERS ] if not wug_performers: continue colour = hkd.get_oshi_colour( ctx.guild, list(hkd.WUG_ROLE_IDS.keys()) [hkd.WUG_MEMBERS.index(wug_performers[0]) - 1]) if len( wug_performers) == 1 else Colour.teal() if first: first = False await ctx.send( '**Events Involving WUG Members on {0:%Y}-{0:%m}-{0:%d} ({0:%A})**' .format(search_date.replace(year=search_year))) await asyncio.sleep(0.5) other_performers = [ p for p in performers if p not in hkd.WUG_MEMBERS and p not in hkd.WUG_OTHER_UNITS ] embed_fields = [] embed_fields.append(('Location', info[1].contents[0])) embed_fields.append( ('Time', event_time.contents[0] if event_time else 'To be announced')) embed_fields.append( ('WUG Members', ', '.join(wug_performers))) embed_fields.append( ('Other Performers', ', '.join(other_performers) if other_performers else 'None')) embed_fields.append(('Eventernote Attendees', event[3].find('p').contents[0])) event_urls.append(event_url) await asyncio.sleep(0.5) await ctx.send(embed=hkd.create_embed( title=info[0].contents[0], colour=colour, url='https://www.eventernote.com{0}'.format( event_url), thumbnail=event[0].find('img')['src'], fields=embed_fields, inline=True)) break if not event_urls: await ctx.send(embed=hkd.create_embed( description="Couldn't find any events on that day.", colour=Colour.red()))
class Misc(commands.Cog): def __init__(self, bot, config): self.bot = bot self.config = config @cog_ext.cog_slash( description="Translate the provided Japanese text into English via Google Translate.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option( name="text", description="The text to translate.", option_type=3, required=True ) ] ) async def translate(self, ctx: SlashContext, text: str): await ctx.defer() await ctx.send(embed=hkd.create_embed(description=Translator().translate(text, src='ja', dest='en').text)) @cog_ext.cog_slash( description="Convert currency from one type to another.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option( name="conversion", description="Convert amount of currency-a to currency-b.", option_type=3, required=True ) ] ) async def currency(self, ctx: SlashContext, conversion: str): await ctx.defer() conversion_split = conversion.split() if len(conversion_split) == 4 and conversion_split[2].lower() == 'to': with suppress(Exception): result = CurrencyRates().convert(conversion_split[1].upper(), conversion_split[3].upper(), Decimal(conversion_split[0])) await ctx.send(embed=hkd.create_embed(title='{0} {1}'.format('{:f}'.format(result).rstrip('0').rstrip('.'), conversion_split[3].upper()))) return await ctx.send(embed=hkd.create_embed(description="Couldn't convert. Please follow this format for converting currency: **/currency** 12.34 AUD to USD.", colour=Colour.red())) @cog_ext.cog_slash( description="Show weather information for the specified location.", guild_ids=hkd.get_all_guild_ids(), options=[ create_option( name="location", description="The location to show the weather for.", option_type=3, required=True ) ] ) async def weather(self, ctx: SlashContext, location: str): await ctx.defer() if len(query := location.split(',')) > 1: with suppress(Exception): query[1] = countries.get(name=query[1].strip().title()).alpha_2 with suppress(Exception): result = requests.get('http://api.openweathermap.org/data/2.5/weather', params={'q': ','.join(query), 'APPID': self.config['weather_api_key']}).json() timezone = pytz.timezone(TimezoneFinder().timezone_at(lat=result['coord']['lat'], lng=result['coord']['lon'])) embed_fields = [] embed_fields.append(('Weather', '{0}'.format(result['weather'][0]['description'].title()))) embed_fields.append(('Temperature', '{0} °C, {1} °F'.format('{0:.2f}'.format(float(result['main']['temp']) - 273.15), '{0:.2f}'.format((1.8 * (float(result['main']['temp']) - 273.15)) + 32.0)))) embed_fields.append(('Humidity', '{0}%'.format(result['main']['humidity']))) embed_fields.append(('Wind Speed', '{0} m/s'.format(result['wind']['speed']))) embed_fields.append(('Sunrise', '{0:%I}:{0:%M} {0:%p}'.format(datetime.fromtimestamp(result['sys']['sunrise'], tz=timezone)))) embed_fields.append(('Sunset', '{0:%I}:{0:%M} {0:%p}'.format(datetime.fromtimestamp(result['sys']['sunset'], tz=timezone)))) embed_fields.append(('Pressure', '{0} hPa'.format(result['main']['pressure']))) await ctx.send(content='**Weather for {0}, {1}**'.format(result['name'], countries.lookup(result['sys']['country']).name), embed=hkd.create_embed(fields=embed_fields, inline=True)) return await ctx.send(embed=hkd.create_embed(description="Couldn't get weather. Please follow this format for checking the weather: **/weather** Melbourne, Australia.", colour=Colour.red()))