Switch to Asyncpg for db con
This commit is contained in:
parent
7949707a3c
commit
51d3f32055
@ -72,11 +72,11 @@ class Admin:
|
||||
emoji_code = f'<a:{emoji.name}:{emoji.id}>'
|
||||
else:
|
||||
emoji_code = f'<:{emoji.name}:{emoji.id}>'
|
||||
if self.bot.db_con.fetch('select id from geeksbot_emojis where id = $1', emoji.id):
|
||||
self.bot.db_con.execute("update geeksbot_emojis set id = $2, name = $1, code = $3 where name = $1",
|
||||
emoji.name, emoji.id, emoji_code)
|
||||
if await self.bot.db_con.fetch('select id from geeksbot_emojis where id = $1', emoji.id):
|
||||
await self.bot.db_con.execute("update geeksbot_emojis set id = $2, name = $1, code = $3 "
|
||||
"where name = $1", emoji.name, emoji.id, emoji_code)
|
||||
else:
|
||||
self.bot.db_con.execute("insert into geeksbot_emojis(id,name,code) values ($2,$1,$3)",
|
||||
await self.bot.db_con.execute("insert into geeksbot_emojis(id,name,code) values ($2,$1,$3)",
|
||||
emoji.name, emoji.id, emoji_code)
|
||||
await ctx.message.add_reaction('✅')
|
||||
await ctx.send(f'Emojis have been updated in the database.')
|
||||
@ -84,7 +84,7 @@ class Admin:
|
||||
@commands.command(hidden=True)
|
||||
@commands.check(checks.is_guild_owner)
|
||||
async def get_guild_config(self, ctx):
|
||||
config = self.bot.db_con.fetchval('select * from guild_config where guild_id = $1', ctx.guild.id)
|
||||
config = await self.bot.db_con.fetchval('select * from guild_config where guild_id = $1', ctx.guild.id)
|
||||
configs = [str(config)[i:i+1990] for i in range(0, len(config), 1990)]
|
||||
await ctx.message.author.send(f'The current config for the {ctx.guild.name} guild is:\n')
|
||||
admin_log.info(configs)
|
||||
@ -112,7 +112,7 @@ class Admin:
|
||||
if ctx.guild:
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
if channel is not None:
|
||||
self.bot.db_con.execute('update guild_config set admin_chat = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set admin_chat = $2 where guild_id = $1',
|
||||
ctx.guild.id, channel.id)
|
||||
await ctx.send(f'{channel.name} is now set as the Admin Chat channel for this guild.')
|
||||
|
||||
@ -121,18 +121,18 @@ class Admin:
|
||||
if ctx.guild:
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
if str(config).lower() == 'true':
|
||||
if self.bot.db_con.fetchval('select allowed_channels from guild_config where guild_id = $1',
|
||||
ctx.guild.id) is []:
|
||||
if await self.bot.db_con.fetchval('select allowed_channels from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id) is []:
|
||||
await ctx.send('Please set at least one allowed channel before running this command.')
|
||||
else:
|
||||
self.bot.db_con.execute('update guild_config set channel_lockdown = True where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
await self.bot.db_con.execute('update guild_config set channel_lockdown = True '
|
||||
'where guild_id = $1', ctx.guild.id)
|
||||
await ctx.send('Channel Lockdown is now active.')
|
||||
elif str(config).lower() == 'false':
|
||||
if self.bot.db_con.fetchval('select channel_lockdown from guild_config where guild_id = $1',
|
||||
if await self.bot.db_con.fetchval('select channel_lockdown from guild_config where guild_id = $1',
|
||||
ctx.guild.id):
|
||||
self.bot.db_con.execute('update guild_config set channel_lockdown = False where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
await self.bot.db_con.execute('update guild_config set channel_lockdown = False '
|
||||
'where guild_id = $1', ctx.guild.id)
|
||||
await ctx.send('Channel Lockdown has been deactivated.')
|
||||
else:
|
||||
await ctx.send('Channel Lockdown is already deactivated.')
|
||||
@ -153,27 +153,29 @@ class Admin:
|
||||
await ctx.send(f'{channel} is not a valid text channel in this guild.')
|
||||
else:
|
||||
admin_log.info('Chan found')
|
||||
if self.bot.db_con.fetchval('select allowed_channels from guild_config where guild_id = $1',
|
||||
ctx.guild.id):
|
||||
if chnl.id in json.loads(self.bot.db_con.fetchval('select allowed_channels '
|
||||
'from guild_config where guild_id = $1',
|
||||
if await self.bot.db_con.fetchval('select allowed_channels from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id):
|
||||
if chnl.id in json.loads(await self.bot.db_con.fetchval('select allowed_channels '
|
||||
'from guild_config '
|
||||
'where guild_id = $1',
|
||||
ctx.guild.id)):
|
||||
admin_log.info('Chan found in config')
|
||||
await ctx.send(f'{channel} is already in the list of allowed channels. Skipping...')
|
||||
else:
|
||||
admin_log.info('Chan not found in config')
|
||||
allowed_channels = json.loads(self.bot.db_con.fetchval('select allowed_channels '
|
||||
allowed_channels = json.loads(await self.bot.db_con.fetchval('select allowed_channels '
|
||||
'from guild_config '
|
||||
'where guild_id = $1',
|
||||
ctx.guild.id)).append(chnl.id)
|
||||
self.bot.db_con.execute('update guild_config set allowed_channels = $2 '
|
||||
ctx.guild.id))\
|
||||
.append(chnl.id)
|
||||
await self.bot.db_con.execute('update guild_config set allowed_channels = $2 '
|
||||
'where guild_id = $1', ctx.guild.id, allowed_channels)
|
||||
added = f'{added}\n{channel}'
|
||||
else:
|
||||
admin_log.info('Chan not found in config')
|
||||
allowed_channels = [chnl.id]
|
||||
self.bot.db_con.execute('update guild_config set allowed_channels = $2 where guild_id = $1',
|
||||
ctx.guild.id, allowed_channels)
|
||||
await self.bot.db_con.execute('update guild_config set allowed_channels = $2 '
|
||||
'where guild_id = $1', ctx.guild.id, allowed_channels)
|
||||
added = f'{added}\n{channel}'
|
||||
if added != '':
|
||||
await ctx.send(f'The following channels have been added to the allowed channel list: {added}')
|
||||
@ -195,7 +197,8 @@ class Admin:
|
||||
async def add_prefix(self, ctx, *, prefix=None):
|
||||
if ctx.guild:
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
prefixes = self.bot.db_con.fetchval('select prefix from guild_config where guild_id = $1', ctx.guild.id)
|
||||
prefixes = await self.bot.db_con.fetchval('select prefix from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
if prefix is None:
|
||||
await ctx.send(prefixes)
|
||||
return
|
||||
@ -207,7 +210,7 @@ class Admin:
|
||||
if len(prefixes) > 10:
|
||||
await ctx.send(f'Only 10 prefixes are allowed per guild.\nPlease remove some before adding more.')
|
||||
prefixes = prefixes[:10]
|
||||
self.bot.db_con.execute('update guild_config set prefix = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set prefix = $2 where guild_id = $1',
|
||||
ctx.guild.id, prefixes)
|
||||
await ctx.guild.me.edit(nick=f'[{prefixes[0]}] Geeksbot')
|
||||
await ctx.send(f"Updated. You currently have {len(prefixes)} "
|
||||
@ -223,7 +226,7 @@ class Admin:
|
||||
async def remove_prefix(self, ctx, *, prefix=None):
|
||||
if ctx.guild:
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
prefixes = self.bot.db_con.fetchval('select prefix from guild_config where guild_id = $1',
|
||||
prefixes = await self.bot.db_con.fetchval('select prefix from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
found = 0
|
||||
if prefix is None:
|
||||
@ -241,7 +244,7 @@ class Admin:
|
||||
else:
|
||||
await ctx.send(f'The prefix {p} is not in the config for this guild.')
|
||||
if found:
|
||||
self.bot.db_con.execute('update guild_config set prefix = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set prefix = $2 where guild_id = $1',
|
||||
ctx.guild.id, prefixes)
|
||||
await ctx.guild.me.edit(nick=f'[{prefixes[0] if len(prefixes) != 0 else self.bot.default_prefix}] '
|
||||
f'Geeksbot')
|
||||
@ -259,13 +262,13 @@ class Admin:
|
||||
async def _add_admin_role(self, ctx, role=None):
|
||||
role = discord.utils.get(ctx.guild.roles, name=role)
|
||||
if role is not None:
|
||||
roles = json.loads(self.bot.db_con.fetchval('select admin_roles from guild_config where guild_id = $1',
|
||||
ctx.guild.id))
|
||||
roles = json.loads(await self.bot.db_con.fetchval('select admin_roles from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if role.name in roles:
|
||||
await ctx.send(f'{role.name} is already registered as an admin role in this guild.')
|
||||
else:
|
||||
roles[role.name] = role.id
|
||||
self.bot.db_con.execute('update guild_config set admin_roles = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set admin_roles = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(roles))
|
||||
await ctx.send(f'{role.name} has been added to the list of admin roles for this guild.')
|
||||
else:
|
||||
@ -277,11 +280,11 @@ class Admin:
|
||||
async def _remove_admin_role(self, ctx, role=None):
|
||||
role = discord.utils.get(ctx.guild.roles, name=role)
|
||||
if role is not None:
|
||||
roles = json.loads(self.bot.db_con.fetchval('select admin_roles from guild_config where guild_id = $1',
|
||||
ctx.guild.id))
|
||||
roles = json.loads(await self.bot.db_con.fetchval('select admin_roles from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if role.name in roles:
|
||||
del roles[role.name]
|
||||
self.bot.db_con.execute('update guild_config set admin_roles = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set admin_roles = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(roles))
|
||||
await ctx.send(f'{role.name} has been removed from the list of admin roles for this guild.')
|
||||
else:
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import json
|
||||
@ -50,10 +51,12 @@ class BotEvents:
|
||||
config_str = f'{config_str}\n{" "*4}{config}: {guild_config[config]}'
|
||||
return config_str
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
async def on_raw_message_delete(self, msg_id, chan_id):
|
||||
await self.bot.db_con.execute('update messages set deleted_at = $1 where id = $2',
|
||||
datetime.utcnow(), msg_id)
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
async def on_raw_bulk_message_delete(self, msg_ids, chan_id):
|
||||
del_time = datetime.utcnow()
|
||||
for msg_id in msg_ids:
|
||||
@ -85,7 +88,8 @@ class BotEvents:
|
||||
await self.bot.db_con.execute(sql, *msg_data)
|
||||
if ctx.guild:
|
||||
if ctx.author != ctx.guild.me:
|
||||
if await self.bot.db_con.fetchval("select pg_filter from guild_config where guild_id = $1", ctx.guild.id):
|
||||
if await self.bot.db_con.fetchval("select pg_filter from guild_config where guild_id = $1",
|
||||
ctx.guild.id):
|
||||
profane = 0
|
||||
for word in await self.bot.db_con.fetchval('select profane_words from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id):
|
||||
@ -144,9 +148,10 @@ class BotEvents:
|
||||
ctx.created_at, ctx.system_content, ctx.author.id, ctx.id]
|
||||
await self.bot.db_con.execute(sql, *msg_data)
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
async def on_command_error(self, ctx, error):
|
||||
import traceback
|
||||
if ctx.channel.id == 418452585683484680 and type(error) == discord.ext.commands.errors.CommandNotFound:
|
||||
if ctx.channel.id == 418452585683484680 and type(error) == commands.errors.CommandNotFound:
|
||||
return
|
||||
for page in utils.paginate(''.join(traceback.format_exception(type(error), error, error.__traceback__))):
|
||||
await ctx.send(page)
|
||||
|
||||
@ -5,8 +5,8 @@ from . import utils
|
||||
owner_id = 351794468870946827
|
||||
|
||||
|
||||
def check_admin_role(bot, ctx, member):
|
||||
admin_roles = json.loads(bot.db_con.fetchval(f"select admin_roles from guild_config where guild_id = $1",
|
||||
async def check_admin_role(bot, ctx, member):
|
||||
admin_roles = json.loads(await bot.db_concon.fetchval(f"select admin_roles from guild_config where guild_id = $1",
|
||||
ctx.guild.id))
|
||||
for role in admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in member.roles:
|
||||
@ -14,17 +14,17 @@ def check_admin_role(bot, ctx, member):
|
||||
return member.id == ctx.guild.owner.id or member.id == owner_id
|
||||
|
||||
|
||||
def check_rcon_role(bot, ctx, member):
|
||||
rcon_admin_roles = json.loads(bot.db_con.fetchval("select rcon_admin_roles from guild_config where guild_id = $1",
|
||||
ctx.guild.id))
|
||||
async def check_rcon_role(bot, ctx, member):
|
||||
rcon_admin_roles = json.loads(await bot.db_concon.fetchval("select rcon_admin_roles from guild_config "
|
||||
"where guild_id = $1", ctx.guild.id))
|
||||
for role in rcon_admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=rcon_admin_roles[role]) in member.roles:
|
||||
return True
|
||||
return member.id == ctx.guild.owner.id or member.id == owner_id
|
||||
|
||||
|
||||
def is_admin(bot, ctx):
|
||||
admin_roles = json.loads(bot.db_con.fetchval("select admin_roles from guild_config where guild_id = $1",
|
||||
async def is_admin(bot, ctx):
|
||||
admin_roles = json.loads(await bot.db_concon.fetchval("select admin_roles from guild_config where guild_id = $1",
|
||||
ctx.guild.id))
|
||||
for role in admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in ctx.message.author.roles:
|
||||
@ -32,15 +32,15 @@ def is_admin(bot, ctx):
|
||||
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
|
||||
|
||||
|
||||
def is_guild_owner(ctx):
|
||||
async def is_guild_owner(ctx):
|
||||
if ctx.guild:
|
||||
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
|
||||
return False
|
||||
|
||||
|
||||
def is_rcon_admin(bot, ctx):
|
||||
rcon_admin_roles = json.loads(bot.db_con.fetchval("select rcon_admin_roles from guild_config where guild_id = $1",
|
||||
ctx.guild.id))
|
||||
async def is_rcon_admin(bot, ctx):
|
||||
rcon_admin_roles = json.loads(await bot.db_concon.fetchval("select rcon_admin_roles from guild_config "
|
||||
"where guild_id = $1", ctx.guild.id))
|
||||
for role in rcon_admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=rcon_admin_roles[role]) in ctx.message.author.roles:
|
||||
return True
|
||||
|
||||
@ -28,6 +28,7 @@ async def mute(bot, ctx, admin=0, member_id=None):
|
||||
|
||||
|
||||
def to_list_of_str(items, out: list=list(), level=1, recurse=0):
|
||||
# noinspection PyShadowingNames
|
||||
def rec_loop(item, key, out, level):
|
||||
quote = '"'
|
||||
if type(item) == list:
|
||||
|
||||
@ -17,8 +17,8 @@ class Patreon:
|
||||
@commands.cooldown(1, 5, type=commands.BucketType.user)
|
||||
async def get_patreon_links(self, ctx, target: discord.Member=None):
|
||||
"""Prints Patreon information for creators on the server."""
|
||||
if self.bot.db_con.fetchval('select patreon_enabled from guild_config where guild_id = $1', ctx.guild.id):
|
||||
patreon_info = self.bot.db_con.fetchval('select patreon_message,patreon_links from guild_config '
|
||||
if await self.bot.db_con.fetchval('select patreon_enabled from guild_config where guild_id = $1', ctx.guild.id):
|
||||
patreon_info = await self.bot.db_con.fetchval('select patreon_message,patreon_links from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id)
|
||||
message = patreon_info[0].replace('\\n', '\n')
|
||||
patreon_links = json.loads(patreon_info[1])
|
||||
@ -34,12 +34,12 @@ class Patreon:
|
||||
@commands.command(aliases=['patreon_message'])
|
||||
async def set_patreon_message(self, ctx, message):
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
patreon_message = self.bot.db_con.fetchval('select patreon_message from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
patreon_message = await self.bot.db_con.fetchval('select patreon_message from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id)
|
||||
if message == patreon_message:
|
||||
await ctx.send('That is already the current message for this guild.')
|
||||
else:
|
||||
self.bot.db_con.execute('update guild_config set patreon_message = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set patreon_message = $2 where guild_id = $1',
|
||||
ctx.guild.id, message)
|
||||
await ctx.send(f'The patreon message for this guild has been set to:\n{message}')
|
||||
else:
|
||||
@ -48,7 +48,7 @@ class Patreon:
|
||||
@commands.command(aliases=['add_patreon', 'set_patreon'])
|
||||
async def add_patreon_info(self, ctx, name, url):
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
patreon_info = self.bot.db_con.fetchval('select patreon_links from guild_config where guild_id = $1',
|
||||
patreon_info = await self.bot.db_con.fetchval('select patreon_links from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
patreon_links = {}
|
||||
update = 0
|
||||
@ -57,7 +57,7 @@ class Patreon:
|
||||
if name in patreon_links:
|
||||
update = 1
|
||||
patreon_links[name] = url
|
||||
self.bot.db_con.execute('update guild_config set patreon_links = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set patreon_links = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(patreon_links))
|
||||
await ctx.send(f"The Patreon link for {name} has been "
|
||||
f"{'updated to the new url.' if update else'added to the config for this guild.'}")
|
||||
@ -67,13 +67,13 @@ class Patreon:
|
||||
@commands.command(aliases=['remove_patreon'])
|
||||
async def remove_patreon_info(self, ctx, name):
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
patreon_info = self.bot.db_con.fetchval('select patreon_links from guild_config where guild_id = $1',
|
||||
patreon_info = await self.bot.db_con.fetchval('select patreon_links from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
if patreon_info:
|
||||
patreon_links = json.loads(patreon_info)
|
||||
if name in patreon_links:
|
||||
del patreon_links[name]
|
||||
self.bot.db_con.execute('update guild_config set patreon_links = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set patreon_links = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(patreon_links))
|
||||
await ctx.send(f'The Patreon link for {name} has been removed from the config for this guild.')
|
||||
return
|
||||
@ -87,16 +87,16 @@ class Patreon:
|
||||
@commands.command()
|
||||
async def enable_patreon(self, ctx, state: bool=True):
|
||||
if checks.is_admin(self.bot, ctx):
|
||||
patreon_status = self.bot.db_con.fetchval('select patreon_enabled from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
patreon_status = await self.bot.db_con.fetchval('select patreon_enabled from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id)
|
||||
if patreon_status and state:
|
||||
await ctx.send('Patreon is already enabled for this guild.')
|
||||
elif patreon_status and not state:
|
||||
self.bot.db_con.execute('update guild_config set patreon_enabled = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set patreon_enabled = $2 where guild_id = $1',
|
||||
ctx.guild.id, state)
|
||||
await ctx.send('Patreon has been disabled for this guild.')
|
||||
elif not patreon_status and state:
|
||||
self.bot.db_con.execute('update guild_config set patreon_enabled = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set patreon_enabled = $2 where guild_id = $1',
|
||||
ctx.guild.id, state)
|
||||
await ctx.send('Patreon has been enabled for this guild.')
|
||||
elif not patreon_status and not state:
|
||||
@ -106,8 +106,9 @@ class Patreon:
|
||||
@commands.cooldown(1, 5, type=commands.BucketType.user)
|
||||
async def referral_links(self, ctx, target: discord.Member=None):
|
||||
"""Prints G-Portal Referral Links."""
|
||||
if self.bot.db_con.fetchval('select referral_enabled from guild_config where guild_id = $1', ctx.guild.id):
|
||||
referral_info = self.bot.db_con.fetchval('select referral_message,referral_links from guild_config '
|
||||
if await self.bot.db_con.fetchval('select referral_enabled from guild_config where guild_id = $1',
|
||||
ctx.guild.id):
|
||||
referral_info = await self.bot.db_con.fetchval('select referral_message,referral_links from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id)
|
||||
message = referral_info[0]
|
||||
referral_links = json.loads(referral_info[1])
|
||||
|
||||
43
exts/rcon.py
43
exts/rcon.py
@ -140,12 +140,13 @@ class Rcon:
|
||||
To view all the valid ARK servers for this guild see list_ark_servers."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
if server is not None:
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections '
|
||||
'from guild_config where guild_id = $1',
|
||||
ctx.guild.id))
|
||||
server = server.replace('_', ' ').title()
|
||||
if server in rcon_connections:
|
||||
rcon_connections[server]["monitoring_chat"] = 1
|
||||
self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(rcon_connections))
|
||||
channel = self.bot.get_channel(rcon_connections[server]['game_chat_chan_id'])
|
||||
await channel.send('Started monitoring on the {0} server.'.format(server))
|
||||
@ -182,7 +183,7 @@ class Rcon:
|
||||
message = func(ctx, message, rcon_connections['server'])
|
||||
await channel.send('{0}'.format(message))
|
||||
await asyncio.sleep(1)
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections '
|
||||
'from guild_config '
|
||||
'where guild_id = $1',
|
||||
ctx.guild.id))
|
||||
@ -201,12 +202,13 @@ class Rcon:
|
||||
Context is the same as monitor_chat"""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
if server is not None:
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections '
|
||||
'from guild_config where guild_id = $1',
|
||||
ctx.guild.id))
|
||||
server = server.replace('_', ' ').title()
|
||||
if server in rcon_connections:
|
||||
rcon_connections[server]["monitoring_chat"] = 0
|
||||
self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(rcon_connections))
|
||||
else:
|
||||
await ctx.send(f'Server not found: {server}')
|
||||
@ -228,7 +230,7 @@ class Rcon:
|
||||
"first last"
|
||||
To view all the valid ARK servers for this guild see list_ark_servers."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if server is not None:
|
||||
server = server.replace('_', ' ').title()
|
||||
@ -267,7 +269,7 @@ class Rcon:
|
||||
All strings (<server>, <ip>, <password>) must be contained inside double quotes."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
server = server.title()
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if server not in rcon_connections:
|
||||
rcon_connections[server] = {
|
||||
@ -279,7 +281,7 @@ class Rcon:
|
||||
'msg_chan_id': 0,
|
||||
'monitoring_chat': 0
|
||||
}
|
||||
self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(rcon_connections))
|
||||
await ctx.send('{0} server has been added to my configuration.'.format(server))
|
||||
else:
|
||||
@ -296,11 +298,11 @@ class Rcon:
|
||||
All strings <server> must be contained inside double quotes."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
server = server.title()
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if server in rcon_connections:
|
||||
del rcon_connections[server]
|
||||
self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(rcon_connections))
|
||||
await ctx.send('{0} has been removed from my configuration.'.format(server))
|
||||
else:
|
||||
@ -316,8 +318,9 @@ class Rcon:
|
||||
Example: 76561198024193239,76561198024193239,76561198024193239"""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
if steam_ids is not None:
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections '
|
||||
'from guild_config where guild_id = $1',
|
||||
ctx.guild.id))
|
||||
error = 0
|
||||
error_msg = ''
|
||||
success_msg = 'Adding to the running whitelist on all servers.'
|
||||
@ -362,7 +365,7 @@ class Rcon:
|
||||
If a server is not specified it will default to running saveworld on all servers in the guild\'s config.
|
||||
Will print out "World Saved" for each server when the command completes successfully."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
success_msg = 'Running saveworld'
|
||||
if server is None:
|
||||
@ -404,7 +407,7 @@ class Rcon:
|
||||
The message will be prefixed with the Discord name of the person running the command.
|
||||
Will print "Success" for each server once the broadcast is sent."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if message is not None:
|
||||
message = f'{ctx.author.display_name}: {message}'
|
||||
@ -441,7 +444,7 @@ class Rcon:
|
||||
If <server> has more than one word in it's name it will either need to be surrounded
|
||||
by double quotes or the words separated by _"""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if server is not None:
|
||||
server = server.replace('_', ' ').title()
|
||||
@ -479,7 +482,7 @@ class Rcon:
|
||||
These channels will be added to the guild's rcon config and are where the
|
||||
server chat messages will be sent when monitor_chat is run."""
|
||||
if checks.is_rcon_admin(self.bot, ctx):
|
||||
rcon_connections = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
rcon_connections = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
edited = 0
|
||||
category = discord.utils.get(ctx.guild.categories, name='Server Chats')
|
||||
@ -503,7 +506,7 @@ class Rcon:
|
||||
rcon_connections[server]['game_chat_chan_id'] = chan.id
|
||||
edited = 1
|
||||
if edited == 1:
|
||||
self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
await self.bot.db_con.execute('update guild_config set rcon_connections = $2 where guild_id = $1',
|
||||
ctx.guild.id, json.dumps(rcon_connections))
|
||||
await ctx.message.add_reaction('✅')
|
||||
else:
|
||||
@ -514,7 +517,7 @@ class Rcon:
|
||||
@commands.check(checks.is_restricted_chan)
|
||||
async def list_ark_servers(self, ctx):
|
||||
"""Returns a list of all the ARK servers in the current guild\'s config."""
|
||||
servers = json.loads(self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
servers = json.loads(await self.bot.db_con.fetchval('select rcon_connections from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
em = discord.Embed(style='rich',
|
||||
title=f'__**There are currently {len(servers)} ARK servers in my config:**__',
|
||||
|
||||
@ -242,18 +242,18 @@ class Utils:
|
||||
if ctx.guild:
|
||||
if request_msg is not None:
|
||||
if len(request_msg) < 1000:
|
||||
self.bot.db_con.execute('insert into admin_requests (issuing_member_id, guild_orig, request_text,'
|
||||
'request_time) values ($1, $2, $3, $4)',
|
||||
await self.bot.db_con.execute('insert into admin_requests (issuing_member_id, guild_orig, '
|
||||
'request_text, request_time) values ($1, $2, $3, $4)',
|
||||
ctx.author.id, ctx.guild.id, request_msg, ctx.message.created_at)
|
||||
channel = self.bot.db_con.fetchval(f'select admin_chat from guild_config where guild_id = $1',
|
||||
channel = await self.bot.db_con.fetchval(f'select admin_chat from guild_config where guild_id = $1',
|
||||
ctx.guild.id)
|
||||
if channel:
|
||||
chan = discord.utils.get(ctx.guild.channels, id=channel)
|
||||
msg = ''
|
||||
admin_roles = []
|
||||
roles = self.bot.db_con.fetchval(f'select admin_roles,rcon_admin_roles from guild_config where '
|
||||
f'$1', ctx.guild.id)
|
||||
request_id = self.bot.db_con.fetchval(f'select id from admin_requests where '
|
||||
roles = await self.bot.db_con.fetchval(f'select admin_roles,rcon_admin_roles from guild_config '
|
||||
f'where $1', ctx.guild.id)
|
||||
request_id = await self.bot.db_con.fetchval(f'select id from admin_requests where '
|
||||
f'issuing_member_id = $1 and request_time = $2',
|
||||
ctx.author.id, ctx.message.created_at)
|
||||
for item in roles:
|
||||
@ -294,7 +294,7 @@ class Utils:
|
||||
)
|
||||
if checks.is_admin(self.bot, ctx) or checks.is_rcon_admin(self.bot, ctx):
|
||||
if assigned_to is None:
|
||||
requests = self.bot.db_con.fetch(f'select * from admin_requests where guild_orig = $1 '
|
||||
requests = await self.bot.db_con.fetch(f'select * from admin_requests where guild_orig = $1 '
|
||||
f'and completed_time is null', ctx.guild.id)
|
||||
em.title = f'Admin help requests for {ctx.guild.name}'
|
||||
if requests:
|
||||
@ -314,7 +314,7 @@ class Utils:
|
||||
else:
|
||||
if checks.check_admin_role(self.bot, ctx, assigned_to)\
|
||||
or checks.check_rcon_role(self.bot, ctx, assigned_to):
|
||||
requests = self.bot.db_con.fetch('select * from admin_requests where assigned_to = $1 '
|
||||
requests = await self.bot.db_con.fetch('select * from admin_requests where assigned_to = $1 '
|
||||
'and guild_orig = $2 and completed_time is null',
|
||||
assigned_to.id, ctx.guild.id)
|
||||
em.title = f'Admin help requests assigned to {assigned_to.display_name} in {ctx.guild.name}'
|
||||
@ -328,13 +328,14 @@ class Utils:
|
||||
"",
|
||||
inline=False)
|
||||
else:
|
||||
em.add_field(name=f'There are no pending requests for {assigned_to.display_name} on this guild.',
|
||||
em.add_field(name=f'There are no pending requests for '
|
||||
f'{assigned_to.display_name} on this guild.',
|
||||
value='',
|
||||
inline=False)
|
||||
else:
|
||||
em.title = f'{assigned_to.display_name} is not an admin in this guild.'
|
||||
else:
|
||||
requests = self.bot.db_con.fetch('select * from admin_requests where issuing_member_id = $1 '
|
||||
requests = await self.bot.db_con.fetch('select * from admin_requests where issuing_member_id = $1 '
|
||||
'and guild_orig = $2 and completed_time is null',
|
||||
ctx.author.id, ctx.guild.id)
|
||||
em.title = f'Admin help requests for {ctx.author.display_name}'
|
||||
@ -367,11 +368,12 @@ class Utils:
|
||||
except ValueError:
|
||||
await ctx.send(f'{request_id} is not a valid request id.')
|
||||
else:
|
||||
request = self.bot.db_con.fetchval(f'select * from admin_requests where id = $1', request_id)
|
||||
request = await self.bot.db_con.fetchval(f'select * from admin_requests where id = $1',
|
||||
request_id)
|
||||
if request:
|
||||
if request[3] == ctx.guild.id:
|
||||
if request[6] is None:
|
||||
self.bot.db_con.execute('update admin_requests set completed_time = $1 where '
|
||||
await self.bot.db_con.execute('update admin_requests set completed_time = $1 where '
|
||||
'id = $2', ctx.message.created_at, request_id)
|
||||
await ctx.send(f'Request {request_id} by '
|
||||
f'{ctx.guild.get_member(request[1]).display_name}'
|
||||
@ -454,7 +456,8 @@ class Utils:
|
||||
def is_me(message):
|
||||
if message.author == self.bot.user:
|
||||
return True
|
||||
prefixes = self.bot.db_con.fetchval('select prefix from guild_config where guild_id = $1', ctx.guild.id)
|
||||
prefixes = self.bot.loop.create_task(self.bot.db_con.fetchval('select prefix from guild_config '
|
||||
'where guild_id = $1', ctx.guild.id))
|
||||
if prefixes:
|
||||
for prefix in prefixes:
|
||||
if message.content.startswith(prefix):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user