mirror of
https://github.com/AsgardEternal/DiscordWhitelist.git
synced 2024-12-28 22:29:13 -06:00
move interaction
This commit is contained in:
parent
40dd8e0c45
commit
c9c4aca402
@ -1,12 +1,14 @@
|
||||
import discord
|
||||
import random
|
||||
import logging
|
||||
|
||||
import mysql.connector
|
||||
|
||||
from autowl import config
|
||||
from autowl.bot import Bot
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -15,6 +17,7 @@ class Group(commands.Cog, name="group"):
|
||||
self.client = client
|
||||
|
||||
async def baseperm(self, interaction: discord.Interaction, role: discord.Role, perms: str):
|
||||
|
||||
await interaction.response.send_message("Whitelist group successfully added/updated")
|
||||
if role.id in self.client.whitelistGrps.keys():
|
||||
self.client.whitelistGrps[role.id].squadPerms = perms
|
||||
@ -25,11 +28,13 @@ class Group(commands.Cog, name="group"):
|
||||
name=role.name, roleID=role.id, permissions=perms
|
||||
)
|
||||
|
||||
squadjs = mysql.connector.connect(user='squadjs', password=self.client.mysqlpass,
|
||||
host='asgard.orion-technologies.io', database='squadjs', use_pure=False)
|
||||
membsup = []
|
||||
for memb in role.members:
|
||||
membsup.append(memb.id)
|
||||
if len(membsup) > 0:
|
||||
memupcur = self.client.squadjs.cursor(buffered=True)
|
||||
memupcur = squadjs.cursor(buffered=True)
|
||||
in_params = ','.join(['%s'] * len(membsup))
|
||||
sqlstate = "SELECT * FROM DBLog_SteamUsers WHERE discordID IN (%s)" % in_params
|
||||
log.info(sqlstate)
|
||||
@ -39,13 +44,14 @@ class Group(commands.Cog, name="group"):
|
||||
for data in udata:
|
||||
self.client.whitelistGrps[role.id].addMember(config.WhitelistMember(data[2], data[1], data[0]))
|
||||
|
||||
self.client.squadjs.commit()
|
||||
squadjs.commit()
|
||||
squadjs.close()
|
||||
|
||||
@app_commands.command()
|
||||
async def add(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
role: discord.Role,
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
role: discord.Role,
|
||||
):
|
||||
await self.baseperm(interaction, role, "reserve")
|
||||
|
||||
@ -60,9 +66,9 @@ class Group(commands.Cog, name="group"):
|
||||
|
||||
@app_commands.command()
|
||||
async def remove(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
role: discord.Role,
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
role: discord.Role,
|
||||
):
|
||||
if not self.client.whitelistGrps.get(role.id):
|
||||
await interaction.response.send_message(
|
||||
|
@ -18,12 +18,13 @@ class Whitelist(commands.Cog):
|
||||
|
||||
@app_commands.command()
|
||||
async def link(self, interaction: discord.Interaction, steam64: str):
|
||||
squadjs = mysql.connector.connect(user='squadjs', password=self.client.mysqlpass, host='asgard.orion-technologies.io', database='squadjs', use_pure=False)
|
||||
if not interaction.guild:
|
||||
await interaction.response.send_message(
|
||||
"This command must be ran within a discord server!"
|
||||
)
|
||||
return
|
||||
updatecur = self.client.squadjs.cursor(buffered=True)
|
||||
updatecur = squadjs.cursor(buffered=True)
|
||||
try:
|
||||
updatecur.execute(self.client.squadjs_updateDiscordID, (interaction.user.id, steam64))
|
||||
rowsaffected = updatecur.rowcount
|
||||
@ -37,7 +38,7 @@ class Whitelist(commands.Cog):
|
||||
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.")
|
||||
self.client.squadjs.commit()
|
||||
squadjs.commit()
|
||||
return
|
||||
except mysql.connector.Error as err:
|
||||
log.error("MYSQL error!")
|
||||
@ -47,5 +48,6 @@ class Whitelist(commands.Cog):
|
||||
if urole.id in self.client.whitelistGrps.keys():
|
||||
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))
|
||||
self.client.squadjs.commit()
|
||||
squadjs.commit()
|
||||
squadjs.close()
|
||||
await interaction.response.send_message(f"discord is linked to steamID, roles updated.")
|
||||
|
@ -39,7 +39,7 @@ class Bot(commands.Bot):
|
||||
intents=intents,
|
||||
help_command=commands.DefaultHelpCommand(dm_help=True),
|
||||
)
|
||||
self.squadjs = mysql.connector.connect(user='squadjs', password=mysqlpass, host='asgard.orion-technologies.io', database='squadjs', use_pure=False)
|
||||
self.mysqlpass = mysqlpass
|
||||
|
||||
async def on_command(self, ctx: commands.Context):
|
||||
log.info(f"{ctx.author} ({ctx.author.id}) invoked command: {ctx.command.name}, {ctx.message}")
|
||||
|
Loading…
Reference in New Issue
Block a user