2023-02-05 04:32:26 -06:00
|
|
|
import discord
|
2023-02-22 22:14:17 -06:00
|
|
|
import logging
|
2023-04-17 20:46:53 -05:00
|
|
|
|
|
|
|
import mysql.connector
|
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
from autowl import config
|
|
|
|
from autowl.bot import Bot
|
|
|
|
from discord.ext import commands
|
|
|
|
from discord import app_commands
|
|
|
|
|
|
|
|
|
2023-02-22 22:14:17 -06:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
class Whitelist(commands.Cog):
|
|
|
|
def __init__(self, client: Bot):
|
|
|
|
self.client = client
|
|
|
|
|
|
|
|
@app_commands.command()
|
2023-04-17 20:46:53 -05:00
|
|
|
async def link(self, interaction: discord.Interaction, steam64: str):
|
2023-08-01 21:17:23 -05:00
|
|
|
self.client.squadjs.connect()
|
2023-02-22 22:14:17 -06:00
|
|
|
if not interaction.guild:
|
|
|
|
await interaction.response.send_message(
|
|
|
|
"This command must be ran within a discord server!"
|
|
|
|
)
|
|
|
|
return
|
2023-08-01 21:17:23 -05:00
|
|
|
updatecur = self.client.squadjs.cursor(buffered=True)
|
2023-04-17 20:46:53 -05:00
|
|
|
try:
|
2023-04-17 22:11:05 -05:00
|
|
|
updatecur.execute(self.client.squadjs_updateDiscordID, (interaction.user.id, steam64))
|
|
|
|
rowsaffected = updatecur.rowcount
|
2023-04-17 21:40:13 -05:00
|
|
|
if rowsaffected <= 0:
|
2023-04-17 22:30:18 -05:00
|
|
|
updatecur.execute(self.client.squadjs_findByDiscordID, [interaction.user.id])
|
|
|
|
if updatecur.rowcount <= 0:
|
|
|
|
await interaction.response.send_message("Cound not find SteamID!")
|
|
|
|
else:
|
|
|
|
for urole in interaction.user.roles:
|
|
|
|
if urole.id in self.client.whitelistGrps.keys():
|
|
|
|
self.client.whitelistGrps[urole.id].members[f"{interaction.user.id}"].steam64 = steam64
|
|
|
|
self.client.whitelistGrps[urole.id].updateGroup()
|
|
|
|
await interaction.response.send_message("SteamID already linked, roles updated.")
|
2023-08-01 21:17:23 -05:00
|
|
|
self.client.squadjs.commit()
|
2023-04-17 21:36:32 -05:00
|
|
|
return
|
2023-04-17 20:46:53 -05:00
|
|
|
except mysql.connector.Error as err:
|
|
|
|
log.error("MYSQL error!")
|
2023-04-17 21:36:32 -05:00
|
|
|
await interaction.response.send_message("There was an internal server error, pls contact skillet")
|
2023-04-17 21:24:22 -05:00
|
|
|
return
|
2023-04-17 20:46:53 -05:00
|
|
|
for urole in interaction.user.roles:
|
|
|
|
if urole.id in self.client.whitelistGrps.keys():
|
2023-04-17 21:18:38 -05:00
|
|
|
disusername = interaction.user.nick if interaction.user.nick is not None else interaction.user.name
|
|
|
|
self.client.whitelistGrps[urole.id].addMember(config.WhitelistMember(interaction.user.id, disusername, steam64))
|
2023-08-01 21:17:23 -05:00
|
|
|
self.client.squadjs.commit()
|
|
|
|
self.client.squadjs.close()
|
2023-04-18 00:07:24 -05:00
|
|
|
await interaction.response.send_message(f"discord is linked to steamID, roles updated.")
|