Writing variables to a file to check on an error
This commit is contained in:
parent
48a753cf26
commit
4f6e1b7ea5
|
@ -1,7 +1,6 @@
|
|||
from discord.ext import commands
|
||||
from .utils import config
|
||||
from .utils import checks
|
||||
import discord
|
||||
import subprocess
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
@ -92,7 +91,7 @@ class Core:
|
|||
await self.bot.say(response)
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
async def roll(self, ctx, notation: str = "d6"):
|
||||
async def roll(self, ctx, notation: str="d6"):
|
||||
"""Rolls a die based on the notation given
|
||||
Format should be #d#"""
|
||||
try:
|
||||
|
@ -111,7 +110,7 @@ class Core:
|
|||
if num > 100:
|
||||
await self.bot.say("What die has more than 100 sides? Please, calm down")
|
||||
return
|
||||
|
||||
|
||||
valueStr = ", ".join("{}".format(random.randint(1, num)) for i in range(0, int(dice)))
|
||||
|
||||
if int(dice) == 1:
|
||||
|
|
72
cogs/mod.py
72
cogs/mod.py
|
@ -2,25 +2,28 @@ from discord.ext import commands
|
|||
from .utils import checks
|
||||
from .utils import config
|
||||
import pymysql
|
||||
import traceback
|
||||
import discord
|
||||
|
||||
valid_perms = ['kick_members','ban_members','administrator','manage_channels','manage_server','read_messages',
|
||||
'send_messages','send_tts_messages','manage_messages','embed_links','attach_files','read_message_history',
|
||||
'mention_everyone','connect','speak','mute_members','deafen_members','move_members','use_voice_activation',
|
||||
'change_nicknames','manage_nicknames','manage_roles']
|
||||
valid_perms = ['kick_members', 'ban_members', 'administrator', 'manage_channels', 'manage_server', 'read_messages',
|
||||
'send_messages', 'send_tts_messages', 'manage_messages', 'embed_links', 'attach_files',
|
||||
'read_message_history',
|
||||
'mention_everyone', 'connect', 'speak', 'mute_members', 'deafen_members', 'move_members',
|
||||
'use_voice_activation',
|
||||
'change_nicknames', 'manage_nicknames', 'manage_roles']
|
||||
|
||||
|
||||
class Mod:
|
||||
"""Commands that can be used by a or an admin, depending on the command"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
|
||||
@commands.group(pass_context=True)
|
||||
async def nsfw(self, ctx):
|
||||
"""Handles adding or removing a channel as a nsfw channel"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await self.bot.say('Invalid subcommand passed: {0.subcommand_passed}'.format(ctx))
|
||||
|
||||
|
||||
@nsfw.command(name="add", pass_context=True)
|
||||
@commands.has_permissions(kick_members=True)
|
||||
async def nsfw_add(self, ctx):
|
||||
|
@ -35,7 +38,7 @@ class Mod:
|
|||
return
|
||||
config.closeConnection()
|
||||
await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)")
|
||||
|
||||
|
||||
@nsfw.command(name="remove", aliases=["delete"], pass_context=True)
|
||||
@commands.has_permissions(kick_members=True)
|
||||
async def nsfw_remove(self, ctx):
|
||||
|
@ -51,7 +54,7 @@ class Mod:
|
|||
cursor.execute('delete from nsfw_channels where channel_id="{}"'.format(ctx.message.channel.id))
|
||||
config.closeConnection()
|
||||
await self.bot.say("This channel has just been unregistered as a nsfw channel")
|
||||
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
@commands.has_permissions(manage_server=True)
|
||||
async def leave(self, ctx):
|
||||
|
@ -66,16 +69,16 @@ class Mod:
|
|||
msg = ' '.join(msg)
|
||||
await self.bot.say(msg)
|
||||
await self.bot.delete_message(ctx.message)
|
||||
|
||||
|
||||
@commands.group(pass_context=True, invoke_without_command=True)
|
||||
async def perms(self, ctx, command: str = ""):
|
||||
async def perms(self, ctx, command: str=""):
|
||||
if command == "":
|
||||
await self.bot.say("Valid permissions are: ```{}```".format("\n".join("{}".format(i) for i in valid_perms)))
|
||||
return
|
||||
if command not in self.bot.commands:
|
||||
await self.bot.say("{} does not appear to be a valid command!".format(command))
|
||||
return
|
||||
|
||||
|
||||
cursor = config.getCursor()
|
||||
cursor.execute('use {}'.format(config.db_perms))
|
||||
cursor.execute("show tables like '{}'".format(ctx.message.server.id))
|
||||
|
@ -83,48 +86,53 @@ class Mod:
|
|||
if result is None:
|
||||
await self.bot.say("There are no custom permissions setup on this server yet!")
|
||||
return
|
||||
sql = "select perms from `"+ctx.message.server.id+"` where command=%s"
|
||||
sql = "select perms from `" + ctx.message.server.id + "` where command=%s"
|
||||
cursor.execute(sql, (command,))
|
||||
result = cursor.fetchone()
|
||||
if result is None:
|
||||
await self.bot.say("That command has no custom permissions setup on it!")
|
||||
return
|
||||
|
||||
await self.bot.say("You need to have the permission `{}` to use the command `{}` in this server".format(result['perms'],command))
|
||||
|
||||
|
||||
await self.bot.say(
|
||||
"You need to have the permission `{}` to use the command `{}` in this server".format(result['perms'],
|
||||
command))
|
||||
|
||||
@perms.command(name="add", aliases=["setup,create"], pass_context=True)
|
||||
@commands.has_permissions(manage_server=True)
|
||||
async def add_perms(self, ctx, command: str, permissions: str):
|
||||
for checks in self.bot.commands.get(command).checks:
|
||||
if "isOwner" == checks.__name__:
|
||||
for check in self.bot.commands.get(command).checks:
|
||||
if "isOwner" == check.__name__:
|
||||
await self.bot.say("This command cannot have custom permissions setup!")
|
||||
return
|
||||
|
||||
|
||||
if getattr(discord.Permissions, permissions, None) is None and not permissions.lower() == "none":
|
||||
await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```{}```"
|
||||
.format(permissions, "\n".join(valid_perms)))
|
||||
.format(permissions, "\n".join(valid_perms)))
|
||||
else:
|
||||
cursor = config.getCursor()
|
||||
cursor.execute('use {}'.format(config.db_perms))
|
||||
cursor.execute("show tables like %s", (ctx.message.server.id,))
|
||||
result = cursor.fetchone()
|
||||
if result is None:
|
||||
#Server's data doesn't exist yet, need to create it
|
||||
sql = "create table `"+ctx.message.server.id+"` (`command` varchar(32) not null,`perms` varchar(32) not null,primary key (`command`)) engine=InnoDB default charset=utf8 collate=utf8_bin"
|
||||
# Server's data doesn't exist yet, need to create it
|
||||
sql = "create table `" + ctx.message.server.id + "` (`command` varchar(32) not null,`perms` " \
|
||||
"varchar(32) not null,primary key (`command`))" \
|
||||
" engine=InnoDB default charset=utf8 collate=utf8_bin"
|
||||
cursor.execute(sql)
|
||||
sql = "insert into `"+ctx.message.server.id+"` (command, perms) values(%s, %s)"
|
||||
cursor.execute(sql,(command,permissions))
|
||||
sql = "insert into `" + ctx.message.server.id + "` (command, perms) values(%s, %s)"
|
||||
cursor.execute(sql, (command, permissions))
|
||||
else:
|
||||
sql = "select perms from `"+ctx.message.server.id+"`where command=%s"
|
||||
cursor.execute(sql,(command,))
|
||||
sql = "select perms from `" + ctx.message.server.id + "`where command=%s"
|
||||
cursor.execute(sql, (command,))
|
||||
if cursor.fetchone() is None:
|
||||
sql = "insert into `"+ctx.message.server.id+"` (command, perms) values(%s, %s)"
|
||||
cursor.execute(sql,(command,permissions))
|
||||
sql = "insert into `" + ctx.message.server.id + "` (command, perms) values(%s, %s)"
|
||||
cursor.execute(sql, (command, permissions))
|
||||
else:
|
||||
sql = "update `"+ctx.message.server.id+"` set perms=%s where command=%s"
|
||||
cursor.execute(sql,(permissions,command))
|
||||
|
||||
await self.bot.say("I have just added your custom permissions; you now need to have `{}` permissions to use the command `{}`".format(permissions, command))
|
||||
sql = "update `" + ctx.message.server.id + "` set perms=%s where command=%s"
|
||||
cursor.execute(sql, (permissions, command))
|
||||
|
||||
await self.bot.say("I have just added your custom permissions; "
|
||||
"you now need to have `{}` permissions to use the command `{}`".format(permissions, command))
|
||||
config.closeConnection()
|
||||
|
||||
|
||||
|
|
|
@ -5,29 +5,35 @@ from . import config
|
|||
def isOwner(ctx):
|
||||
return ctx.message.author.id == config.ownerID
|
||||
|
||||
|
||||
def customPermsOrRole(perm):
|
||||
def predicate(ctx):
|
||||
nonlocal perm
|
||||
cursor = config.getCursor()
|
||||
cursor.execute('use {}'.format(config.db_perms))
|
||||
cmd = str(ctx.command)
|
||||
sid = ctx.message.server.id
|
||||
f = open("/home/phxntx5/public_html/Bonfire/checkstest.txt","r+")
|
||||
f.write("cmd: {}\nsid: {}".format(cmd, sid))
|
||||
f.close()
|
||||
|
||||
cursor.execute("show tables like %s", (sid,))
|
||||
result = cursor.fetchone()
|
||||
if result is not None:
|
||||
sql = "select perms from `"+sid+"`where command=%s"
|
||||
cursor.execute(sql,(cmd,))
|
||||
sql = "select perms from `"+sid+"` where command=%s"
|
||||
cursor.execute(sql, (cmd,))
|
||||
result = cursor.fetchone()
|
||||
perm = result['perms']
|
||||
if perm == "none":
|
||||
return True
|
||||
config.closeConnection()
|
||||
for role in ctx.message.author.roles:
|
||||
if getattr(role,perm):
|
||||
if getattr(role, perm):
|
||||
return True
|
||||
return False
|
||||
return commands.check(predicate)
|
||||
|
||||
|
||||
|
||||
def isPM():
|
||||
def predicate(ctx):
|
||||
return ctx.message.channel.is_private
|
||||
|
|
Loading…
Reference in a new issue