Skip to content

Commit

Permalink
Merge pull request #124 from kelvin-codes-stuff:Welcome-message-general
Browse files Browse the repository at this point in the history
Added custom #general welcome message system
  • Loading branch information
AeroBytesNL authored Jan 12, 2024
2 parents 3411e39 + f64508d commit f4f1131
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 57 deletions.
2 changes: 1 addition & 1 deletion GitHubAction/GitHubPteroScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
api = PterodactylClient(gamemanager_url, gamemanager_client_password)

# Assigning server ID
SERVER_ID = "6cfbb9d3"
SERVER_ID = "84e463df"

# Killing the individual server
api.client.servers.send_power_action(SERVER_ID, "kill")
Expand Down
86 changes: 32 additions & 54 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# TODO change user.name to general name to prefend errors

class modmail(commands.Cog):


def __init__(self, bot: commands.Bot):
self.bot = bot
print("Cog ModMail is loaded!")
Expand All @@ -20,12 +18,9 @@ def __init__(self, bot: commands.Bot):
# On message
@commands.Cog.listener()
async def on_message(self, message):


# Cancels if message did come from a bot
if message.author == self.bot.user or message.author.bot:
return


# if message is in DM
if isinstance(message.channel, disnake.channel.DMChannel):
Expand All @@ -44,7 +39,6 @@ async def on_message(self, message):
await modmail.first_contact(self, message)
return


# if message is in a thread
if hasattr(message, "thread"):
if not isinstance(message.channel, disnake.channel.DMChannel):
Expand All @@ -59,11 +53,8 @@ async def on_message(self, message):
await modmail.close_ticket_and_thread(self, message, member)



# First contact
async def first_contact(self, message):

# Button class
class Confirm(disnake.ui.View):

def __init__(self):
Expand All @@ -81,39 +72,27 @@ async def cancel(self_inside_button, button: disnake.ui.Button, inter: disnake.M
await inter.response.send_message("Ik heb het geannuleert!")
self_inside_button.stop()


# Creating instance
view = Confirm()

if message.attachments:
embed=disnake.Embed(title="Contact ADT&G beheer", description="Wil je dit versturen?", color=disnake.Color.green())
embed.add_field(name="Tekst:", value=message.clean_content)
embed.set_image(url=message.attachments[0].url)
await message.channel.send(embed=embed, view=view)
return


# Embed
embed=disnake.Embed(title="Contact ADT&G beheer", description="Wil je dit versturen?", color=disnake.Color.green())
embed.add_field(name=f"Vraag:", value=str(message.clean_content), inline=True)
await message.channel.send(embed=embed, view=view)



# Making thread
async def create_contact_with_staff(self, message):

# Button class
class Confirm(disnake.ui.View):

def __init__(self):
super().__init__(timeout=0)

@disnake.ui.button(label="Accepteren", style=disnake.ButtonStyle.green)
async def confirm(self_inside_button, button: disnake.ui.Button, inter: disnake.MessageInteraction):
await inter.response.send_message("Ik heb het verzoek geaccepteert!")
# Starting make thread function
await modmail.accept_or_deny(self, message, type=True, by_user=inter.author.name)

@disnake.ui.button(label="Afwijzen", style=disnake.ButtonStyle.grey)
async def cancel(self_inside_button, button: disnake.ui.Button, inter: disnake.MessageInteraction):
msg = await inter.response.send_message("Ik heb het verzoek afgewezen!")
Expand All @@ -123,39 +102,48 @@ async def cancel(self_inside_button, button: disnake.ui.Button, inter: disnake.M
await thread_to_close.edit(name=f"(gesloten){name_thread}", locked=True, archived=True)
await modmail.accept_or_deny(self, message, type=False, by_user=inter.author.name)


# Creating instance
view = Confirm()


# Get admin and mod roles
guild = await self.bot.fetch_guild(env_variable.GUILD_ID)
role_admin = guild.get_role(Role_ids.ADMIN)
role_moderator = guild.get_role(Role_ids.MODERATOR)


channel = self.bot.get_channel(env_variable.MODMAIL_ID)
msg = await channel.send(f"Nieuwe ModMail ticket") # , allowed_mentions=disnake.AllowedMentions(roles=True)
thread = await channel.create_thread(name=f"{str(message.author.name)}&&MM", reason=f"ModMail for {message.author.name}", type=None, message=msg)

class Deny(disnake.ui.View):

def __init__(self):
super().__init__(timeout=0)


@disnake.ui.button(label="Afwijzen", style=disnake.ButtonStyle.grey)
async def cancel(self_inside_button, button: disnake.ui.Button, inter: disnake.MessageInteraction):
msg = await inter.response.send_message("Ik heb het verzoek afgewezen!")
thread_to_close= self.bot.get_channel(inter.channel.id)
name_thread = thread_to_close.name

await thread_to_close.edit(name=f"(gesloten){name_thread}", locked=True, archived=True)
await modmail.accept_or_deny(self, message, type=False, by_user=inter.author.name)

view = Deny()

# If message is an image
if message.attachments:
embed=disnake.Embed(title="Contact ADT&G beheer", description=f"Van user: {message.author.name}", color=disnake.Color.red())
embed=disnake.Embed(title="Nieuwe ticket", description=f"Van user: {message.author.name}", color=disnake.Color.red())
embed.add_field(name="Tekst:", value=message.clean_content)
embed.set_image(url=message.attachments[0].url)
await thread.send(embed=embed)
await thread.send(embed=embed, view=Deny)
return


# Embed
embed=disnake.Embed(title="Contact ADT&G beheer", description=f"Van user: {message.author.name}", color=disnake.Color.red())
embed=disnake.Embed(title="Nieuwe ticket", description=f"Van user: {message.author.name}", color=disnake.Color.red())
embed.add_field(name=f"Vraag:", value=str(message.clean_content), inline=True)
await thread.send(embed=embed, view=view)
await thread.send(embed=embed, view=Deny)



# Deny or accept request from user
async def accept_or_deny(self, message, type, by_user):

if type == True:
embed=disnake.Embed(title="Contact ADT&G beheer", description=f"Verzoek geaccepteerd door `{by_user}`! Het kan even duren voor je antwoord krijgt.", color=disnake.Color.green())
else:
Expand All @@ -164,10 +152,8 @@ async def accept_or_deny(self, message, type, by_user):
await message.channel.send(embed=embed)



# Sending response from ticket handler to end user
async def send_admin_response_to_ticket_maker(self, message, member):

embed=disnake.Embed(title=f"Contact ADT&G antwoord", description=f"Door beheerder: `{message.author.name}`", color=disnake.Color.green())
embed.add_field(name=f"Antwoord beheer:", value=str(message.clean_content), inline=False)
embed.add_field(name=f"Info:", value="Als je vraag niet beantwoord is, dan kun je hieronder gewoon terugtypen! (In 1 bericht)", inline=False)
Expand All @@ -178,8 +164,6 @@ async def send_admin_response_to_ticket_maker(self, message, member):

# Closing thread
async def close_ticket_and_thread(self, message, member):

# Button class
class Confirm(disnake.ui.View):

def __init__(self):
Expand All @@ -198,18 +182,21 @@ async def confirm(self_inside_button, button: disnake.ui.Button, inter: disnake.
await thread_to_close.edit(name=f"(gesloten){name_thread}", locked=True, archived=True)
self_inside_button.stop()


# Creating instance
view = Confirm()


if message.attachments:
embed=disnake.Embed(title="Je hebt dit gestuurd:", description=str(message.clean_content), color=disnake.Color.green())
embed.set_image(url=message.attachments[0].url)
await message.channel.send(embed=embed, view=view)
await message.delete()
return

embed=disnake.Embed(title="Je hebt dit gestuurd:", description=str(message.clean_content), color=disnake.Color.green())
await message.channel.send(embed=embed, view=view)

await message.delete()


async def send_user_response(self, message, thread_to_send):
# Button class
class Confirm(disnake.ui.View):

def __init__(self):
Expand All @@ -228,31 +215,22 @@ async def confirm(self_inside_button, button: disnake.ui.Button, inter: disnake.
await thread_to_close.edit(name=f"(gesloten){name_thread}", locked=True, archived=True)
self_inside_button.stop()


# Creating instance
view = Confirm()


if message.attachments:
print("Jeej")
embed=disnake.Embed(title="User reageerde met de afbeelding:", description=str(message.clean_content), color=disnake.Color.red())
embed.set_image(url=message.attachments[0].url)

embed.set_image(url=message.attachments[0].url)
await thread_to_send.send(embed=embed, view=view)
return


embed=disnake.Embed(title="User reageerde:", description=str(message.clean_content), color=disnake.Color.red())
await thread_to_send.send(embed=embed, view=view)



# Log modmail actions to LOG channel
async def logging(self, from_user, interaction, on_user):
print(from_user, interaction, on_user)




def setup(bot: commands.Bot):
bot.add_cog(modmail(bot))
36 changes: 36 additions & 0 deletions cogs/welcome_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import disnake
from disnake.ext import commands
from env import Channel


class Welcome_message(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
print("Cog Welcome_message is loaded!")
self.joined_members = []


@commands.Cog.listener()
async def on_member_join(self, member):
self.joined_members.append(member.id)


@commands.Cog.listener()
async def on_member_update(self, before, after):
if before.pending != True and after.pending != False:
return

if before.id not in self.joined_members:
return

self.joined_members.remove(before.id)

general_channel = await self.bot.fetch_channel(Channel.GENERAL)
joined_user = await self.bot.get_or_fetch_user(before.id)
bot_user = await self.bot.get_or_fetch_user(self.bot.user.id)

await general_channel.send(f"Welkom {joined_user} in All Day Tech & Gaming.\n\nIn onze server maken we gebruik van verschillende kanalen om onderwerpen gescheiden te houden:\n- Hulp nodig met tech? <#1019678705045471272>\n- Voor tech gesprekken zie <#723556858820034612>\n- Voor game gesprekken zie <#759456512165937183>\nMocht je vragen hebben m.b.t het beheer dan kun je {bot_user.mention} DM'en!")


def setup(bot: commands.Bot):
bot.add_cog(Welcome_message(bot))
2 changes: 1 addition & 1 deletion database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Database:
password = secure.DATABASE_PASSWORD,
database = secure.DATABASE_NAME,
auth_plugin="mysql_native_password"

)
cursor = db.cursor(buffered=True)
print(cursor)
except Exception as e:
print(e)
pass
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def keep_sql_active():
bot.load_extension("cogs.quiz")
bot.load_extension("cogs.bump_reminder")
bot.load_extension("cogs.introduce_remover")

bot.load_extension("cogs.welcome_message")


# Running the bot and starting thread
Expand Down

0 comments on commit f4f1131

Please sign in to comment.