Skip to content

Commit

Permalink
Merge pull request #67 from murpii/master
Browse files Browse the repository at this point in the history
A few fixes and changes
  • Loading branch information
murpii authored Dec 12, 2023
2 parents 6be8b6c + d1c4dfc commit aac8f2c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 100 deletions.
85 changes: 25 additions & 60 deletions cogs/helpcmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,6 @@ async def skins(self, ctx: commands.Context):

await ctx.send(file=file, embed=embed)

@commands.command()
async def kog(self, ctx: commands.Context):
file = discord.File('data/avatar.png', filename='avatar.png')

embed = discord.Embed(
title="King of Gores / KoG",
description="DDNet and KoG aren't affiliated."
"\n\nIf you require assistance on a server within the KoG tab, "
"join their Discord server by clicking on the link below.",
colour=discord.Colour.random())
embed.add_field(
name="URL:",
value="https://discord.kog.tw/")

embed.set_thumbnail(url='attachment://avatar.png')

await ctx.send(file=file, embed=embed)

@commands.command()
async def binds(self, ctx: commands.Context):
file = discord.File('data/avatar.png', filename='avatar.png')
Expand Down Expand Up @@ -146,58 +128,41 @@ async def crash(self, ctx: commands.Context):

await ctx.send(file=file, embed=embed)

@commands.command(name='login')
@commands.command(aliases=['kog', 'login', 'registration'])
async def kog_login(self, ctx: commands.Context):
file = discord.File('data/avatar.png', filename='avatar.png')

embed = discord.Embed(
title="KoG Login and Account Migration",
description="",
title="KoG registration and login",
description="First and foremost: DDNet and KoG aren't affiliated.\n"
"You are not required to log-in on a DDNet server.\n\n"
"If you need help on a server related to KoG, "
"join their Discord server by clicking on the link below.",
colour=discord.Colour.random())

embed.add_field(
name='',
value='If you already had an account on KoG, watch the following video: [www.youtube.com](https://www.youtube.com/watch?v=d1kbt-srlac)',
inline=False
)
name="URL:",
value="https://discord.kog.tw/",
inline=False)

embed.add_field(
name=f'For new Players:',
value=f'First create an Account:'
f'\n1. Click on the following link: [kog.tw](https://kog.tw/register.php)'
f'\n2. Enter your in-game name, your e-mail address and a password'
f'\n3. If the name is not already registered, you should now receive a message that the "name has been pre-claimed"'
f'\n4. Join the KoG discord server: [KoG Discord](https://discord.kog.tw)'
f'\n5. Create a ticket in KoG\'s discord by clicking on the registration button in #create-a-ticket channel, so a moderator can confirm you.'
f'\n6. Now go to the login page: [kog.tw](https://kog.tw/login.php) and login with the credentials you have used to register.'
f'\n7. Click on your name in the top right-hand corner of the website and select "Dashboard"'
f'\n8. Scroll down to accept the ToS (Terms of Service)'
)
name="Registration process:",
value="https://discord.com/channels/342003344476471296/941355528242749440/1129043200527569018",
inline=True)

embed.add_field(
name='Migration Guide:',
value='1. Click on the following link: [kog.tw](https://auth.kog.tw/)'
'\n2. Click the register button and fill in all your information (Note: You can put anything in First name and Surname. Does not need to be your real information)'
'\n3. After clicking the next button you should receive an e-mail with a code.'
'\n4. Open the e-mail and click the blue button or copy the code'
'\n5. You should now see "User activated" - click next and login'
'\n6. Now you can choose if you want to use two factor authentication (Optional, but recommended)'
'\n7. Navigate back to this link [kog.tw](https://kog.tw/) login and click the start migration button'
'\n8. Now there should be a blue "next" button - click that button then click the blue start migration button.'
'\n9. You should now receive an e-mail from KoG - click on the "migrate now" button.'
'\n10. Now click the blue "login to kog one" button and then login with your zitadel account.'
'\n11. It should now say: "Account successfully queued for migration."'
'\n12. You\'re done.',
inline=True
)
name="Migration process:",
value="https://discord.com/channels/342003344476471296/941355528242749440/1129043332211945492",
inline=True)

embed.add_field(
name='How to Login:',
value='1. Click on the following link: [kog.tw](https://kog.tw/login.php) and log in.'
'\n2. Click on your name in the top right-hand corner and select "Ingame login".'
'\n3. Click on the yellow button saying "generate a login".'
'\n4. Join any KoG server and paste the /login command',
inline=False
)
name="How to login on KoG servers:",
value="https://discord.com/channels/342003344476471296/941355528242749440/1129043447517564978",
inline=True)

embed.add_field(
name=f'This is not required on DDNet.',
value=f'',
name="Video Guide:",
value="https://www.youtube.com/watch?v=d1kbt-srlac",
inline=False)
embed.set_thumbnail(url='attachment://avatar.png')

Expand Down
55 changes: 23 additions & 32 deletions cogs/ticketsystem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

from discord.ext import commands, tasks
from datetime import datetime, timedelta, timezone
from typing import Union

from cogs.ticketsystem.buttons import MainMenu
from cogs.ticketsystem.close import CloseButton, process_ticket_closure
from cogs.ticketsystem.subscribe import SubscribeMenu
from utils.transcript import transcript

GUILD_DDNET = 252358080522747904
CAT_TICKETS = 1124657181363556403
CAT_MODERATION = 968484659950403585
CHAN_MODERATOR = 345588928482508801
ROLE_ADMIN = 293495272892399616
ROLE_DISCORD_MODERATOR = 737776812234506270
Expand All @@ -32,26 +31,25 @@
def is_staff(member: discord.Member) -> bool:
return any(role.id in (ROLE_ADMIN, ROLE_DISCORD_MODERATOR, ROLE_MODERATOR) for role in member.roles)

def extract_servers(json, tags, network):
server_list = None
if network == "ddnet":
server_list = json.get('servers')
elif network == "kog":
server_list = json.get('servers-kog')

all_servers = []
for address in server_list:
server = address.get('servers')
for tag in tags:
server_lists = server.get(tag)
if server_lists is not None:
all_servers += server_lists
return all_servers

def server_link(addr):
jsondata = requests.get("https://info.ddnet.org/info", timeout=1).json()

def extract_servers(json, tags, network):
server_list = None
if network == "ddnet":
server_list = json.get('servers')
elif network == "kog":
server_list = json.get('servers-kog')

all_servers = []
for address in server_list:
server = address.get('servers')
for tag in tags:
server_lists = server.get(tag)
if server_lists is not None:
all_servers += server_lists
return all_servers

ddnet = extract_servers(jsondata, ['DDNet', 'Test', 'Tutorial'], "ddnet")
ddnetpvp = extract_servers(jsondata, ['Block', 'Infection', 'iCTF', 'gCTF', 'Vanilla', 'zCatch',
'TeeWare', 'TeeSmash', 'Foot', 'xPanic', 'Monster'], "ddnet")
Expand All @@ -63,10 +61,10 @@ def extract_servers(json, tags, network):

if re_match[0] in ddnet:
message_text = f'{re_match[0]} is an official DDNet server. ' \
f'\n<steam://run/412220//{re_match[0]}>/'
f'\n<https://ddnet.org/connect-to/?addr={re_match[0]}/>'
elif re_match[0] in ddnetpvp:
message_text = f'{re_match[0]} is an official DDNet PvP server. ' \
f'\n<steam://run/412220//{re_match[0]}>/'
f'\n<https://ddnet.org/connect-to/?addr={re_match[0]}/>'
elif re_match[0] in kog:
message_text = f'{re_match[0]} appears to be a KoG server. DDNet and KoG aren\'t affiliated. ' \
f'\nJoin their discord and ask for help there instead. <https://discord.kog.tw/>'
Expand Down Expand Up @@ -219,6 +217,7 @@ async def close(self, ctx, *, message=None):
ticket_creator_id = int(ctx.channel.topic.split(": ")[1].strip("<@!>"))

if not is_staff(ctx.author) and ctx.author.id != ticket_creator_id:
await ctx.channel.send('This ticket does not belong to you.')
return

ticket_channel = self.bot.get_channel(ctx.channel.id)
Expand Down Expand Up @@ -301,21 +300,15 @@ async def close(self, ctx, *, message=None):
f"(ID: {ticket_creator_id}). Removed Channel named {ctx.channel.name} (ID: {ctx.channel.id})"
)

# TODO: Notify a ticket creator that no one is available to assist them with their issue. (Late at night)
@tasks.loop(hours=1)
async def check_inactive_tickets(self):
ticket_data_copy = self.ticket_data.get("tickets", {}).copy()
for user_id, ticket_data in ticket_data_copy.items():
for ticket_user_id, ticket_data in list(self.ticket_data.get("tickets", {}).items()):
channel_ids = ticket_data.get("channel_ids", [])
inactivity_count = ticket_data.get("inactivity_count", {})

for channel_id, ticket_category in channel_ids:
ticket_channel = self.bot.get_channel(channel_id)

topic = ticket_channel.topic
ticket_creator_id = int(topic.split(": ")[1].strip("<@!>"))
ticket_creator = await self.bot.fetch_user(ticket_creator_id)

now = datetime.utcnow().replace(tzinfo=timezone.utc)

recent_messages = []
Expand All @@ -331,7 +324,7 @@ async def check_inactive_tickets(self):

if inactivity_count[str(channel_id)] == 2:
await ticket_channel.send(
f'<@{ticket_creator.id}>, this ticket is about to be closed due to inactivity.'
f'<@{ticket_user_id}>, this ticket is about to be closed due to inactivity.'
f'\nIf your report or question has been resolved, consider closing '
f'this ticket yourself by typing $close.'
f'\n**To keep this ticket active, please reply to this message.**'
Expand All @@ -340,8 +333,9 @@ async def check_inactive_tickets(self):

if inactivity_count[str(channel_id)] >= 6:
transcript_file, zip_file = await transcript(self.bot, ticket_channel)
ticket_creator = await self.bot.fetch_user(ticket_user_id)
ticket_category = process_ticket_closure(self, ticket_channel.id,
ticket_creator_id=ticket_creator_id)
ticket_creator_id=ticket_user_id)

if transcript_file:
await ticket_channel.send(f'Uploading files...')
Expand Down Expand Up @@ -410,9 +404,6 @@ async def check_inactive_tickets(self):
f" Removed channel named {ticket_channel.name} (ID: {ticket_channel.id}), due to inactivity."
)

with open(self.ticket_data_file, "w") as f:
json.dump(self.ticket_data, f, indent=4)

@check_inactive_tickets.before_loop
async def before_check_inactive_tickets(self):
await self.bot.wait_until_ready()
Expand Down
24 changes: 16 additions & 8 deletions cogs/ticketsystem/close.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from discord.ui import Button, button, View
from utils.transcript import transcript

CAT_TICKETS = 1124657181363556403
ROLE_ADMIN = 293495272892399616
ROLE_DISCORD_MODERATOR = 737776812234506270
ROLE_MODERATOR = 252523225810993153
Expand All @@ -18,6 +17,7 @@
TH_COMPLAINTS = 1156218705701785660
TH_OTHER = 1156218815164723261


def is_staff(member: discord.Member) -> bool:
return any(role.id in (ROLE_ADMIN, ROLE_DISCORD_MODERATOR, ROLE_MODERATOR) for role in member.roles)

Expand All @@ -28,13 +28,20 @@ def process_ticket_closure(self, ticket_channel_id, ticket_creator_id):

category = None

for channel_id, category in channel_ids:
if channel_id == ticket_channel_id:
channel_ids.remove([channel_id, category])
break

del ticket_data["inactivity_count"][str(ticket_channel_id)]
ticket_data["ticket_num"] -= 1
try:
for channel_id, category in channel_ids:
if channel_id == ticket_channel_id:
channel_ids.remove([channel_id, category])
break
except KeyError:
logging.info(f'Ticket data for {ticket_channel_id} does not exist')

try:
del ticket_data["inactivity_count"][str(ticket_channel_id)]
ticket_data["ticket_num"] -= 1
except KeyError:
ticket_data.setdefault('channel_ids', []).append([int(ticket_channel_id), category])
logging.info(f'Ticket data for {ticket_channel_id} does not exist')

if ticket_data["ticket_num"] < 1:
self.ticket_data["tickets"].pop(str(ticket_creator_id), None)
Expand Down Expand Up @@ -62,6 +69,7 @@ async def confirm(self, interaction: discord.Interaction, button: Button):
ticket_creator_id = int(interaction.channel.topic.split(": ")[1].strip("<@!>"))

if not is_staff(interaction.user) and interaction.user.id != ticket_creator_id:
await interaction.channel.send('This ticket does not belong to you.')
return

ticket_channel = interaction.client.get_channel(interaction.channel.id)
Expand Down

0 comments on commit aac8f2c

Please sign in to comment.