From 22a73ba0c6dc7177c8c430ce30b03290beb27685 Mon Sep 17 00:00:00 2001 From: Conatum Date: Wed, 26 Jan 2022 12:56:35 +0200 Subject: [PATCH] (meta): Send message on guild join. --- bot/modules/meta/__init__.py | 2 ++ bot/modules/meta/help.py | 7 ++--- bot/modules/meta/join_message.py | 46 ++++++++++++++++++++++++++++++++ bot/modules/meta/lib.py | 5 ++++ bot/modules/meta/links.py | 5 ++-- 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 bot/modules/meta/join_message.py create mode 100644 bot/modules/meta/lib.py diff --git a/bot/modules/meta/__init__.py b/bot/modules/meta/__init__.py index 83c6781c..3803e00a 100644 --- a/bot/modules/meta/__init__.py +++ b/bot/modules/meta/__init__.py @@ -1,5 +1,7 @@ +# flake8: noqa from .module import module from . import help from . import links from . import nerd +from . import join_message diff --git a/bot/modules/meta/help.py b/bot/modules/meta/help.py index 191c5328..161e52c8 100644 --- a/bot/modules/meta/help.py +++ b/bot/modules/meta/help.py @@ -6,6 +6,7 @@ from utils import interactive, ctx_addons # noqa from wards import is_guild_admin from .module import module +from .lib import guide_link # Set the command groups to appear in the help @@ -46,9 +47,9 @@ header = """ [StudyLion](https://bot.studylions.com/) is a fully featured study assistant \ that tracks your study time and offers productivity tools \ such as to-do lists, task reminders, private study rooms, group accountability sessions, and much much more.\n -Use `{ctx.best_prefix}help ` (e.g. `{ctx.best_prefix}help send`) to learn how to use each command, \ - or [click here](https://discord.studylions.com/tutorial) for a comprehensive tutorial. -""" +Use `{{ctx.best_prefix}}help ` (e.g. `{{ctx.best_prefix}}help send`) to learn how to use each command, \ + or [click here]({guide_link}) for a comprehensive tutorial. +""".format(guide_link=guide_link) @module.cmd("help", diff --git a/bot/modules/meta/join_message.py b/bot/modules/meta/join_message.py new file mode 100644 index 00000000..c3cdc18a --- /dev/null +++ b/bot/modules/meta/join_message.py @@ -0,0 +1,46 @@ +import discord + +from cmdClient import cmdClient + +from meta import client, conf +from .lib import guide_link, animation_link + + +message = """ +Thank you for inviting me to your community. +Get started by typing `{prefix}help` to see my commands, and `{prefix}config info` \ + to read about my configuration options! + +To learn how to configure me and use all of my features, \ + make sure to [click here]({guide_link}) to read our full setup guide. + +Remember, if you need any help configuring me, \ + want to suggest a feature, report a bug and stay updated, \ + make sure to join our main support and study server by [clicking here]({support_link}). + +Best of luck with your studies! + +""".format( + guide_link=guide_link, + support_link=conf.bot.get('support_link'), + prefix=client.prefix +) + + +@client.add_after_event('guild_join', priority=0) +async def post_join_message(client: cmdClient, guild: discord.Guild): + if (channel := guild.system_channel) and channel.permissions_for(guild.me).embed_links: + embed = discord.Embed( + description=message + ) + embed.set_author( + name="Hello! My name is Leo", + icon_url="https://cdn.discordapp.com/emojis/933610591459872868.webp" + ) + embed.set_image(url=animation_link) + try: + await channel.send(embed=embed) + except discord.HTTPException: + # Something went wrong sending the hi message + # Not much we can do about this + pass diff --git a/bot/modules/meta/lib.py b/bot/modules/meta/lib.py new file mode 100644 index 00000000..22b42474 --- /dev/null +++ b/bot/modules/meta/lib.py @@ -0,0 +1,5 @@ +guide_link = "https://discord.studylions.com/tutorial" + +animation_link = ( + "https://media.discordapp.net/attachments/879412267731542047/926837189814419486/ezgif.com-resize.gif" +) diff --git a/bot/modules/meta/links.py b/bot/modules/meta/links.py index dc80a6d5..476caf26 100644 --- a/bot/modules/meta/links.py +++ b/bot/modules/meta/links.py @@ -5,6 +5,7 @@ from meta import conf from LionContext import LionContext as Context from .module import module +from .lib import guide_link @module.cmd( @@ -38,7 +39,7 @@ async def cmd_invite(ctx: Context): """ embed = discord.Embed( colour=discord.Colour.orange(), - description=f"Click here] to add me to your server: {conf.bot.get('invite_link')}" + description=f"Click here to add me to your server: {conf.bot.get('invite_link')}" ) embed.add_field( name="Setup tips", @@ -50,7 +51,7 @@ async def cmd_invite(ctx: Context): ).format( prefix=ctx.best_prefix, support=conf.bot.get('support_link'), - guide="https://discord.studylions.com/tutorial" + guide=guide_link ) ) await ctx.reply(embed=embed)