Git rid of useless references, and updated for pep8
This commit is contained in:
parent
362270510f
commit
a9267f106e
18
bot.py
18
bot.py
|
@ -1,8 +1,6 @@
|
|||
#!/usr/local/bin/python3.5
|
||||
|
||||
import discord
|
||||
import traceback
|
||||
import sys
|
||||
from discord.ext import commands
|
||||
from cogs.utils import config
|
||||
|
||||
|
@ -27,7 +25,7 @@ async def on_ready():
|
|||
if channel_id != 0:
|
||||
destination = discord.utils.find(lambda m: m.id == channel_id, bot.get_all_channels())
|
||||
await bot.send_message(destination, "I have just finished restarting!")
|
||||
config.saveContent('restart_server',0)
|
||||
config.saveContent('restart_server', 0)
|
||||
|
||||
|
||||
@bot.event
|
||||
|
@ -44,7 +42,8 @@ async def on_member_join(member):
|
|||
|
||||
@bot.event
|
||||
async def on_member_remove(member):
|
||||
await bot.send_message(member.server, "{0} has left the server, I hope it wasn't because of something I said :c".format(member))
|
||||
await bot.send_message(member.server,
|
||||
"{0} has left the server, I hope it wasn't because of something I said :c".format(member))
|
||||
|
||||
|
||||
@bot.event
|
||||
|
@ -58,15 +57,16 @@ async def on_command_error(error, ctx):
|
|||
elif isinstance(error, commands.CheckFailure):
|
||||
fmt = "You can't tell me what to do!"
|
||||
await bot.send_message(ctx.message.channel, fmt)
|
||||
#elif isinstance(error, commands.CommandInvokeError):
|
||||
#f = open("/home/phxntx5/public_html/Bonfire/error_log", 'w')
|
||||
#print('In {0.command.qualified_name}:'.format(ctx), file=f)
|
||||
#traceback.print_tb(error.original.__traceback__, file=f)
|
||||
#print('{0.__class__.__name__}: {0}'.format(error.original), file=f)
|
||||
# elif isinstance(error, commands.CommandInvokeError):
|
||||
# f = open("/home/phxntx5/public_html/Bonfire/error_log", 'w')
|
||||
# print('In {0.command.qualified_name}:'.format(ctx), file=f)
|
||||
# traceback.print_tb(error.original.__traceback__, file=f)
|
||||
# print('{0.__class__.__name__}: {0}'.format(error.original), file=f)
|
||||
else:
|
||||
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
|
||||
await bot.send_message(ctx.message.channel, fmt.format(type(error).__name__, error))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for e in extensions:
|
||||
bot.load_extension(e)
|
||||
|
|
15
cogs/core.py
15
cogs/core.py
|
@ -41,9 +41,9 @@ class Core:
|
|||
"""Use this to print a random doggo image.
|
||||
Doggo is love, doggo is life."""
|
||||
os.chdir('/home/phxntx5/public_html/Bonfire/images')
|
||||
f = glob.glob('doggo*')[random.randint(0,len(glob.glob('doggo*'))-1)]
|
||||
f = glob.glob('doggo*')[random.randint(0, len(glob.glob('doggo*')) - 1)]
|
||||
f = open(f, 'rb')
|
||||
await self.bot.send_file(ctx.message.channel,f)
|
||||
await self.bot.send_file(ctx.message.channel, f)
|
||||
f.close()
|
||||
|
||||
@commands.command()
|
||||
|
@ -169,10 +169,10 @@ class Core:
|
|||
for t in tags:
|
||||
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
|
||||
t['result'] = tag_result
|
||||
config.saveContent('tags',tags)
|
||||
config.saveContent('tags', tags)
|
||||
return
|
||||
tags.append({'server_id':ctx.message.server.id,'tag':tag,'result':tag_result})
|
||||
config.saveContent('tags',tags)
|
||||
tags.append({'server_id': ctx.message.server.id, 'tag': tag, 'result': tag_result})
|
||||
config.saveContent('tags', tags)
|
||||
await self.bot.say("I have just added the tag `{0}`! You can call this tag by entering !tag {0}".format(tag))
|
||||
|
||||
@tag.command(name='delete', aliases=['remove', 'stop'], pass_context=True, no_pm=True)
|
||||
|
@ -184,12 +184,13 @@ class Core:
|
|||
tags = config.getContent('tags')
|
||||
result = [t for t in tags if t['tag'] == tag and t['server_id'] == ctx.message.server.id]
|
||||
if len(result) == 0:
|
||||
await self.bot.say("The tag {} does not exist! You can't remove something if it doesn't exist...".format(tag))
|
||||
await self.bot.say(
|
||||
"The tag {} does not exist! You can't remove something if it doesn't exist...".format(tag))
|
||||
return
|
||||
for t in tags:
|
||||
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
|
||||
tags.remove(t)
|
||||
config.saveContent('tags',tags)
|
||||
config.saveContent('tags', tags)
|
||||
await self.bot.say('I have just removed the tag `{}`'.format(tag))
|
||||
|
||||
|
||||
|
|
|
@ -33,12 +33,13 @@ def updateBattleRecords(winner, loser):
|
|||
result[1] = str(int(result[1]) + 1)
|
||||
battles[loser.id] = "-".join(result)
|
||||
else:
|
||||
battles = {winner.id:"1-0",loser.id:"0-1"}
|
||||
config.saveContent('battle_records',battles)
|
||||
battles = {winner.id: "1-0", loser.id: "0-1"}
|
||||
config.saveContent('battle_records', battles)
|
||||
|
||||
|
||||
class Interaction:
|
||||
"""Commands that interact with another user"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
|
@ -122,7 +123,7 @@ class Interaction:
|
|||
amount = 1
|
||||
booper_boops = boops.get(ctx.message.author.id)
|
||||
if booper_boops is None:
|
||||
boops[ctx.message.author.id] = {boopee.id:1}
|
||||
boops[ctx.message.author.id] = {boopee.id: 1}
|
||||
elif booper_boops.get(boopee.id) is None:
|
||||
booper_boops[boopee.id] = 1
|
||||
boops[ctx.message.author.id] = booper_boops
|
||||
|
@ -131,7 +132,7 @@ class Interaction:
|
|||
booper_boops[boopee.id] = amount
|
||||
boops[ctx.message.author.id] = booper_boops
|
||||
|
||||
config.saveContent('boops',boops)
|
||||
config.saveContent('boops', boops)
|
||||
fmt = "{0.mention} has just booped you {1.mention}! That's {2} times now!"
|
||||
await self.bot.say(fmt.format(booper, boopee, amount))
|
||||
|
||||
|
|
31
cogs/mod.py
31
cogs/mod.py
|
@ -1,7 +1,6 @@
|
|||
from discord.ext import commands
|
||||
from .utils import checks
|
||||
from .utils import config
|
||||
import pymysql
|
||||
import discord
|
||||
import re
|
||||
|
||||
|
@ -29,19 +28,19 @@ class Mod:
|
|||
await self.bot.say("This channel is already registered as 'nsfw'!")
|
||||
else:
|
||||
nsfw_channels.append(ctx.message.channel.id)
|
||||
config.saveContent('nsfw_channels',nsfw_channels)
|
||||
config.saveContent('nsfw_channels', nsfw_channels)
|
||||
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)
|
||||
@nsfw.command(name="remove", aliases=["delete"], pass_context=True, no_pm=True)
|
||||
@checks.customPermsOrRole("kick_members")
|
||||
async def nsfw_remove(self, ctx, no_pm=True):
|
||||
async def nsfw_remove(self, ctx):
|
||||
"""Removes this channel as a 'nsfw' channel"""
|
||||
nsfw_channels = config.getContent('nsfw_channels')
|
||||
if not ctx.message.channel.id in nsfw_channels:
|
||||
if ctx.message.channel.id not in nsfw_channels:
|
||||
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
|
||||
else:
|
||||
nsfw_channels.remove(ctx.message.channel.id)
|
||||
config.saveContent('nsfw_channels',nsfw_channels)
|
||||
config.saveContent('nsfw_channels', nsfw_channels)
|
||||
await self.bot.say("This channel has just been unregistered as a nsfw channel")
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
|
@ -81,8 +80,8 @@ class Mod:
|
|||
if command_perms is None:
|
||||
await self.bot.say("That command has no custom permissions setup on it!")
|
||||
else:
|
||||
await self.bot.say("You need to have the permission `{}` " \
|
||||
"to use the command `{}` in this server".format(command_perms,command))
|
||||
await self.bot.say("You need to have the permission `{}` "
|
||||
"to use the command `{}` in this server".format(command_perms, command))
|
||||
|
||||
@perms.command(name="add", aliases=["setup,create"], pass_context=True, no_pm=True)
|
||||
@commands.has_permissions(manage_server=True)
|
||||
|
@ -90,11 +89,11 @@ class Mod:
|
|||
"""Sets up custom permissions on the provided command
|
||||
Format must be 'perms add <command> <permission>'
|
||||
If you want to open the command to everyone, provide 'none' as the permission"""
|
||||
command = " ".join(msg[0:len(msg)-1])
|
||||
permissions = msg[len(msg)-1]
|
||||
command = " ".join(msg[0:len(msg) - 1])
|
||||
permissions = msg[len(msg) - 1]
|
||||
if permissions.lower() == "none":
|
||||
permissions = "send_messages"
|
||||
msg = msg[0:len(msg)-1]
|
||||
msg = msg[0:len(msg) - 1]
|
||||
count = 0
|
||||
cmd = self.bot.commands.get(msg[count])
|
||||
while isinstance(cmd, commands.Group):
|
||||
|
@ -105,7 +104,7 @@ class Mod:
|
|||
break
|
||||
|
||||
for check in cmd.checks:
|
||||
if "isOwner" == check.__name__ or re.search("has_permissions",str(check)) is not None:
|
||||
if "isOwner" == check.__name__ or re.search("has_permissions", str(check)) is not None:
|
||||
await self.bot.say("This command cannot have custom permissions setup!")
|
||||
return
|
||||
|
||||
|
@ -119,11 +118,11 @@ class Mod:
|
|||
custom_perms = {}
|
||||
server_perms = custom_perms.get(ctx.message.server.id)
|
||||
if server_perms is None:
|
||||
custom_perms[ctx.message.server.id] = {command:permissions}
|
||||
custom_perms[ctx.message.server.id] = {command: permissions}
|
||||
else:
|
||||
server_perms[command] = permissions
|
||||
custom_perms[ctx.message.server.id] = server_perms
|
||||
config.saveContent('custom_permissions',custom_perms)
|
||||
config.saveContent('custom_permissions', custom_perms)
|
||||
await self.bot.say("I have just added your custom permissions; "
|
||||
"you now need to have `{}` permissions to use the command `{}`".format(permissions, command))
|
||||
|
||||
|
@ -132,7 +131,6 @@ class Mod:
|
|||
async def remove_perms(self, ctx, *command: str):
|
||||
"""Removes the custom permissions setup on the command specified"""
|
||||
cmd = " ".join(command)
|
||||
sid = ctx.message.server.id
|
||||
custom_perms = config.getContent('custom_permissions')
|
||||
if custom_perms is None:
|
||||
await self.bot.say("You do not have custom permissions setup on this server yet!")
|
||||
|
@ -146,8 +144,9 @@ class Mod:
|
|||
await self.bot.say("You do not have custom permissions setup on this command yet!")
|
||||
return
|
||||
del custom_perms[ctx.message.server.id][cmd]
|
||||
config.saveContent('custom_permissions',custom_perms)
|
||||
config.saveContent('custom_permissions', custom_perms)
|
||||
await self.bot.say("I have just removed the custom permissions for {}!".format(cmd))
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Mod(bot))
|
||||
|
|
|
@ -7,14 +7,17 @@ import urllib.parse
|
|||
import urllib.request
|
||||
import urllib.error
|
||||
import json
|
||||
import re
|
||||
|
||||
base_url = "https://owapi.net/api/v2/u/"
|
||||
check_g_stats = ["eliminations","deaths",'kpd','wins','losses','time_played',
|
||||
'cards','damage_done','healing_done','multikills']
|
||||
check_o_stats = ['wins','losses']
|
||||
check_g_stats = ["eliminations", "deaths", 'kpd', 'wins', 'losses', 'time_played',
|
||||
'cards', 'damage_done', 'healing_done', 'multikills']
|
||||
check_o_stats = ['wins', 'losses']
|
||||
|
||||
|
||||
class Overwatch:
|
||||
"""Class for viewing Overwatch stats"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
|
@ -45,7 +48,8 @@ class Overwatch:
|
|||
fmt = "\n".join("{}: {}".format(i, r) for i, r in data['game_stats'].items() if i in check_g_stats)
|
||||
fmt += "\n"
|
||||
fmt += "\n".join("{}: {}".format(i, r) for i, r in data['overall_stats'].items() if i in check_o_stats)
|
||||
await self.bot.say("Overwatch stats for {}: ```py\n{}```".format(user.name, fmt.title().replace("_", " ")))
|
||||
await self.bot.say(
|
||||
"Overwatch stats for {}: ```py\n{}```".format(user.name, fmt.title().replace("_", " ")))
|
||||
else:
|
||||
result = urllib.request.urlopen(base_url + "{}/heroes/{}".format(bt, hero.lower().replace('-', '')))
|
||||
data = json.loads(result.read().decode('utf-8'))
|
||||
|
@ -55,7 +59,7 @@ class Overwatch:
|
|||
await self.bot.say("Overwatch stats for {} using the hero {}: ```py\n{}``` "
|
||||
.format(user.name, hero.title(), fmt.title().replace("_", " ")))
|
||||
except urllib.error.HTTPError as error:
|
||||
error_no = int(re.search("\d+",str(error)).group(0))
|
||||
error_no = int(re.search("\d+", str(error)).group(0))
|
||||
if error_no == 500:
|
||||
await self.bot.say("{} has not used the hero {} before!".format(user.name, hero.title()))
|
||||
elif error_no == 404:
|
||||
|
@ -76,7 +80,7 @@ class Overwatch:
|
|||
return
|
||||
ow = config.getContent('overwatch')
|
||||
ow[ctx.message.author.id] = bt
|
||||
config.saveContent('overwatch',ow)
|
||||
config.saveContent('overwatch', ow)
|
||||
|
||||
await self.bot.say("I have just saved your battletag {}".format(ctx.message.author.mention))
|
||||
|
||||
|
@ -87,7 +91,7 @@ class Overwatch:
|
|||
result = config.getContent('overwatch')
|
||||
if result.get(ctx.message.author.id):
|
||||
del result[ctx.message.author.id]
|
||||
config.saveContent('overwatch',result)
|
||||
config.saveContent('overwatch', result)
|
||||
await self.bot.say("I no longer have your battletag saved {}".format(ctx.message.author.mention))
|
||||
else:
|
||||
await self.bot.say("I don't even have your battletag saved {}".format(ctx.message.author.mention))
|
||||
|
|
|
@ -15,6 +15,7 @@ multi = re.compile(r'```(.*?)```', re.DOTALL)
|
|||
|
||||
class Owner:
|
||||
"""Commands that can only be used by Phantom, bot management commands"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
|
@ -22,20 +23,20 @@ class Owner:
|
|||
@commands.check(checks.isOwner)
|
||||
async def restart(self, ctx):
|
||||
"""Forces the bot to restart"""
|
||||
config.saveContent('restart_server',ctx.message.channel.id)
|
||||
config.saveContent('restart_server', ctx.message.channel.id)
|
||||
await self.bot.say("Restarting; see you in the next life {0}!".format(ctx.message.author.mention))
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@commands.command()
|
||||
@commands.check(checks.isOwner)
|
||||
async def adddoggo(self, ctx, url: str):
|
||||
async def adddoggo(self, url: str):
|
||||
"""Saves a URL as an image to add for the doggo command"""
|
||||
os.chdir('/home/phxntx5/public_html/Bonfire/images')
|
||||
local_path = 'doggo{}.jpg'.format(len(glob.glob('doggo*')))
|
||||
urllib.request.urlretrieve(url,local_path)
|
||||
await self.bot.say("Just saved a new doggo image! You now have {} doggo images!".format(len(glob.glob('doggo*'))))
|
||||
urllib.request.urlretrieve(url, local_path)
|
||||
await self.bot.say(
|
||||
"Just saved a new doggo image! You now have {} doggo images!".format(len(glob.glob('doggo*'))))
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@commands.check(checks.isOwner)
|
||||
|
|
|
@ -3,11 +3,11 @@ from discord.utils import find
|
|||
from .utils import config
|
||||
from .utils import checks
|
||||
import re
|
||||
import pymysql
|
||||
|
||||
|
||||
class Stats:
|
||||
"""Leaderboard/stats related commands"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
|
@ -22,7 +22,7 @@ class Stats:
|
|||
return
|
||||
|
||||
most_boops = 0
|
||||
for b_id,amt in boops.get(ctx.message.author.id).items():
|
||||
for b_id, amt in boops.get(ctx.message.author.id).items():
|
||||
member = find(lambda m: m.id == b_id, self.bot.get_all_members())
|
||||
if member in members and amt > most_boops:
|
||||
most_boops = amt
|
||||
|
@ -42,7 +42,7 @@ class Stats:
|
|||
await self.bot.say("You have not booped anyone {} Why the heck not...?".format(ctx.message.author.mention))
|
||||
return
|
||||
output = "You have booped:"
|
||||
for b_id,amt in boops.get(ctx.message.author.id).items():
|
||||
for b_id, amt in boops.get(ctx.message.author.id).items():
|
||||
member = find(lambda m: m.id == b_id, self.bot.get_all_members())
|
||||
if member in members:
|
||||
output += "\n{0.name}: {1} times".format(member, amt)
|
||||
|
@ -57,7 +57,7 @@ class Stats:
|
|||
count = 0
|
||||
fmt = []
|
||||
if battles is not None:
|
||||
for m_id,record in battles.items():
|
||||
for m_id, record in battles.items():
|
||||
member = find(lambda m: m.id == m_id, self.bot.get_all_members())
|
||||
if member in members:
|
||||
winAmt = int(record.split('-')[0])
|
||||
|
|
|
@ -47,7 +47,7 @@ class Twitch:
|
|||
config.closeConnection()
|
||||
await asyncio.sleep(30)
|
||||
|
||||
@commands.group(no_pm=True, invoke_without_command=True,pass_context=True)
|
||||
@commands.group(no_pm=True, invoke_without_command=True, pass_context=True)
|
||||
@checks.customPermsOrRole("none")
|
||||
async def twitch(self, ctx, *, member: discord.Member=None):
|
||||
"""Use this command to check the twitch info of a user"""
|
||||
|
@ -92,8 +92,9 @@ class Twitch:
|
|||
if result is not None:
|
||||
twitch[ctx.message.author.id]['twitch_url'] = url
|
||||
else:
|
||||
twitch[ctx.message.author.id] = {'twitch_url':url,'server_id':ctx.message.server.id,'notifications_on': 1,'live':0}
|
||||
config.saveContent('twitch',twitch)
|
||||
twitch[ctx.message.author.id] = {'twitch_url': url, 'server_id': ctx.message.server.id,
|
||||
'notifications_on': 1, 'live': 0}
|
||||
config.saveContent('twitch', twitch)
|
||||
await self.bot.say("I have just saved your twitch url {}".format(ctx.message.author.mention))
|
||||
|
||||
@twitch.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
|
||||
|
@ -103,7 +104,7 @@ class Twitch:
|
|||
twitch = config.getContent('twitch')
|
||||
if twitch.get(ctx.message.author.id) is not None:
|
||||
del twitch[ctx.message.author.id]
|
||||
config.saveContent('twitch',twitch)
|
||||
config.saveContent('twitch', twitch)
|
||||
await self.bot.say("I am no longer saving your twitch URL {}".format(ctx.message.author.mention))
|
||||
else:
|
||||
await self.bot.say(
|
||||
|
@ -131,7 +132,7 @@ class Twitch:
|
|||
ctx.message.author.mention))
|
||||
else:
|
||||
twitch[ctx.message.author.id]['notifications_on'] = 1
|
||||
config.saveContent('twitch',twitch)
|
||||
config.saveContent('twitch', twitch)
|
||||
await self.bot.say("I will notify if you go live {}, you'll get a bajillion followers I promise c:".format(
|
||||
ctx.message.author.mention))
|
||||
|
||||
|
@ -144,12 +145,12 @@ class Twitch:
|
|||
await self.bot.say(
|
||||
"I do not have your twitch URL added {}. You can save your twitch url with !twitch add".format(
|
||||
ctx.message.author.mention))
|
||||
elif not result['notifications_on']:
|
||||
elif not twitch.get(ctx.message.author.id)['notifications_on']:
|
||||
await self.bot.say("I am already set to not notify if you go live! Pay attention brah {}".format(
|
||||
ctx.message.author.mention))
|
||||
else:
|
||||
twitch[ctx.message.author.id]['notifications_on'] = 0
|
||||
config.saveContent('twitch',twitch)
|
||||
config.saveContent('twitch', twitch)
|
||||
await self.bot.say(
|
||||
"I will not notify if you go live anymore {}, "
|
||||
"are you going to stream some lewd stuff you don't want people to see?~".format(
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import yaml
|
||||
import pymysql.cursors
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
|
@ -19,18 +18,6 @@ botToken = global_config.get("bot_token", "")
|
|||
ownerID = global_config.get("owner_id", "")
|
||||
|
||||
|
||||
def getCursor():
|
||||
global connection
|
||||
connection = pymysql.connect(host=global_config.get("db_host"), user=global_config.get("db_user"),
|
||||
password=global_config.get("db_user_pass"), charset='utf8mb4',
|
||||
cursorclass=pymysql.cursors.DictCursor)
|
||||
return connection.cursor()
|
||||
|
||||
|
||||
def closeConnection():
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def saveContent(key: str, content):
|
||||
with open("/home/phxntx5/public_html/Bonfire/config.json", "r+") as jf:
|
||||
data = json.load(jf)
|
||||
|
|
Loading…
Reference in a new issue