소스 검색

v0.3.2 Release: New commands for admin cog to finalise ease of use. Cleaned up start up prints and other code. Removed loading of config from cogs' __init__.py.

tags/v0.3.2
roxie 7 년 전
부모
커밋
4b729474f5
7개의 변경된 파일104개의 추가작업 그리고 51개의 파일을 삭제
  1. +73
    -17
      cogs/Admin.py
  2. +11
    -11
      cogs/Twitch.py
  3. +0
    -2
      cogs/__init__.py
  4. +10
    -10
      cogs/selfAssign.py
  5. +1
    -1
      config/config.json
  6. +2
    -5
      config/config.py
  7. +7
    -5
      main.py

+ 73
- 17
cogs/Admin.py 파일 보기

@@ -124,16 +124,16 @@ class Admin():
return await self.bot.say("{} has been set as the twitch shilling channel!".format(channel.mention))

@bot.command(pass_context=True, visible=False)
async def set_customwelcomemessage(self, ctx, *message):
async def set_customwelcomemessage(self, ctx, *, message: str):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
self.con.serverconfig = self.con.load_config()
self.con.serverconfig[ctx.message.server.id]["greets"]["custom_message"] = ' '.join(message)
self.con.serverconfig[ctx.message.server.id]["greets"]["custom_message"] = message
self.con.updateconfig()
return await self.bot.say("Custom message set to '{}'".format(' '.join(message)), delete_after=10)
return await self.bot.say("Custom message set to '{}'".format(message))

@bot.command(pass_context=True, hidden=True)
@bot.command(pass_context=True, hidden=True, aliases=["setava"])
async def changeavatar(self, ctx, url=None):
"""
Usage:
@@ -150,17 +150,73 @@ class Admin():
else:
thing = url.strip('<>')

tempAvaFile = 'tempAva.png'
avaimg = 'avaimg.png'
async with aiohttp.get(thing) as img:
with open(tempAvaFile, 'wb') as f:
with open(avaimg, 'wb') as f:
f.write(await img.read())
with open(tempAvaFile, 'rb') as f:
with open(avaimg, 'rb') as f:
await self.bot.edit_profile(avatar=f.read())
os.remove(tempAvaFile)
os.remove(avaimg)
asyncio.sleep(2)
return await self.bot.say(":ok_hand:")

@bot.command(hidden=True)
@bot.command(pass_context=True, hidden=True, aliases=["nick"])
async def changenickname(self, ctx, *nick):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
if ctx.message.channel.permissions_for(ctx.message.server.me).change_nickname:
await self.bot.change_nickname(ctx.message.server.me, ' '.join(nick))
return await self.bot.say(":thumbsup:")
else:
return await self.bot.say("I don't have permission to do that :sob:", delete_after=self.con.delete_after)

@bot.command(pass_context=True, hidden=True, aliases=["setgame", "game"])
async def changegame(self, ctx, *, game: str):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
if game.lower() == "none":
game_name = None
else:
game_name = discord.Game(name=game)
await self.bot.change_presence(game=game_name, afk=False)
return await self.bot.say(":ok_hand: Game set to {}".format(str(game_name)))

@bot.command(pass_context=True, hidden=True, aliases=["status"])
async def changestatus(self, ctx, status: str):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
status = status.lower()
if status == 'offline' or status == 'invisible':
discordStatus = discord.Status.invisible
elif status == 'idle':
discordStatus = discord.Status.idle
elif status == 'dnd':
discordStatus = discord.Status.dnd
else:
discordStatus = discord.Status.online
await self.bot.change_presence(status=discordStatus)
await self.bot.say("**:ok:** Status set to {}".format(discordStatus))

@bot.command(pass_context=True, hidden=True)
async def echo(self, ctx, channel, *, message: str):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
if ctx.message.channel_mentions:
for channel in ctx.message.channel_mentions:
await self.bot.send_message(channel, content=message)
return await self.bot.say(":point_left:")
elif channel.isdigit():
channel = ctx.message.server.get_channel(channel)
await self.bot.send_message(channel, content=message)
return await self.bot.say(":point_left:")
else:
return await self.bot.say("You did something wrong smh")

@bot.command(pass_context=True, hidden=True)
async def restart(self, ctx):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
@@ -168,7 +224,7 @@ class Admin():
await self.bot.logout()
return os.execl(sys.executable, sys.executable, *sys.argv)

@bot.command(hidden=True)
@bot.command(pass_context=True, hidden=True)
async def shutdown(self, ctx):
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
@@ -183,13 +239,13 @@ class Admin():
"""
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
embed = discord.Embed(title="RoxBot Announcement", colour=discord.Colour(0x306f99), description=' '.join(announcement))
embed.set_footer(text="This message has be automatically generated by a QT Roxie",
icon_url=self.bot.user.avatar_url)
for server in self.bot.servers:
await self.bot.send_message(server, embed=embed)
return await self.bot.say("Done!", delete_after=self.con.delete_after)
else:
embed = discord.Embed(title="RoxBot Announcement", colour=discord.Colour(0x306f99), description=' '.join(announcement))
embed.set_footer(text="This message has be automatically generated by a QT Roxie",
icon_url=self.bot.user.avatar_url)
for server in self.bot.servers:
await self.bot.send_message(server, embed=embed)
return await self.bot.say("Done!", delete_after=self.con.delete_after)


def setup(Bot):

+ 11
- 11
cogs/Twitch.py 파일 보기

@@ -14,15 +14,15 @@ class Twitch():
# Twitch Shilling Part
if blacklisted(member_b):
return
ts_enabled = self.con.serverconfig[member_a.server.id]["twitch_shilling"]["enabled"]
ts_enabled = self.con.serverconfig[member_a.server.id]["twitch"]["enabled"]
if ts_enabled:
if not self.con.serverconfig[member_a.server.id]["twitch_shilling"]["whitelist"][
if not self.con.serverconfig[member_a.server.id]["twitch"]["whitelist"][
"enabled"] or member_a.id in \
self.con.serverconfig[member_a.server.id]["twitch_shilling"]["whitelist"]["list"]:
self.con.serverconfig[member_a.server.id]["twitch"]["whitelist"]["list"]:
if member_a.game:
if member_a.game.type:
channel = discord.Object(
self.con.serverconfig[member_a.server.id]["twitch_shilling"]["twitch-channel"])
self.con.serverconfig[member_a.server.id]["twitch"]["twitch-channel"])
return await self.bot.send_message(channel,
content=":video_game:** {} is live!** :video_game:\n {}\n{}".format(
member_a.name, member_a.game.name, member_a.game.url))
@@ -33,12 +33,12 @@ class Twitch():
return await self.bot.reply("You do not have permission to do this command.", delete_after=20)
else:
self.con.serverconfig = self.con.load_config()
if not self.con.serverconfig[ctx.server.id]["twitch_shilling"]["whitelist"]["enabled"]:
self.con.serverconfig[ctx.server.id]["twitch_shilling"]["whitelist"]["enabled"] = 1
if not self.con.serverconfig[ctx.server.id]["twitch"]["whitelist"]["enabled"]:
self.con.serverconfig[ctx.server.id]["twitch"]["whitelist"]["enabled"] = 1
self.con.updateconfig()
return await self.bot.reply("Whitelist for Twitch shilling has been enabled.")
else:
self.con.serverconfig[ctx.server.id]["twitch_shilling"]["whitelist"]["enabled"] = 0
self.con.serverconfig[ctx.server.id]["twitch"]["whitelist"]["enabled"] = 0
self.con.updateconfig()
return await self.bot.reply("Whitelist for Twitch shilling has been disabled.")

@@ -58,7 +58,7 @@ class Twitch():
if option in ['+', 'add']:
self.con.serverconfig = self.con.load_config()
for user in ctx.message.mentions:
self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"].append(user.id)
self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"].append(user.id)
self.con.updateconfig()
whitelist_count += 1
return await self.bot.say('{} user(s) have been added to the whitelist'.format(whitelist_count))
@@ -66,15 +66,15 @@ class Twitch():
elif option in ['-', 'remove']:
self.con.serverconfig = self.con.load_config()
for user in ctx.message.mentions:
if user.id in self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"]:
self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"].remove(user.id)
if user.id in self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"]:
self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"].remove(user.id)
self.con.updateconfig()
whitelist_count += 1
return await self.bot.say('{} user(s) have been removed to the whitelist'.format(whitelist_count))

elif option == 'list':
return await self.bot.say(
self.con.serverconfig[ctx.message.server.id]["twitch_shilling"]["whitelist"]["list"])
self.con.serverconfig[ctx.message.server.id]["twitch"]["whitelist"]["list"])


def setup(bot):

+ 0
- 2
cogs/__init__.py 파일 보기

@@ -5,5 +5,3 @@ cogs = [
'cogs.selfAssign',
'cogs.Fun'
]
with open('config/config.json', 'r') as config_file:
serverconfig = json.load(config_file)

+ 10
- 10
cogs/selfAssign.py 파일 보기

@@ -22,7 +22,7 @@ class selfAssign():
{command_prefix}listroles
"""
roles = []
for role in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]:
for role in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]:
for serverrole in ctx.message.server.roles:
if role == serverrole.id:
roles.append(serverrole.name)
@@ -38,7 +38,7 @@ class selfAssign():
.iam OverwatchPing
"""
self.con.serverconfig = self.con.load_config()
if not self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["enabled"]:
if not self.con.serverconfig[ctx.message.server.id]["selfAssign"]["enabled"]:
return

user = ctx.message.author
@@ -50,7 +50,7 @@ class selfAssign():
if role in user.roles:
return await self.bot.say("You already have that role.")

if role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]:
if role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]:
await self.bot.add_roles(user, role)
print("{} added {} to themselves in {} on {}".format(user.display_name, role.name, ctx.message.channel,
ctx.message.server))
@@ -68,7 +68,7 @@ class selfAssign():
.iamn OverwatchPing
"""
self.con.serverconfig = self.con.load_config()
if not self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["enabled"]:
if not self.con.serverconfig[ctx.message.server.id]["selfAssign"]["enabled"]:
return

user = ctx.message.author
@@ -77,11 +77,11 @@ class selfAssign():
if role not in server.roles:
return await self.bot.say("That role doesn't exist. Roles are case sensitive. ")

elif role in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]:
elif role in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]:
await self.bot.remove_roles(user, role)
return await self.bot.reply("{} has been successfully removed.".format(role.name))

elif role not in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]:
elif role not in user.roles and role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]:
return await self.bot.reply("You do not have {}.".format(role.name))
else:
return await self.bot.say("That role is not self-assignable.")
@@ -91,10 +91,10 @@ class selfAssign():
if not owner(ctx):
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
if role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]:
if role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]:
return await self.bot.say("{} is already a self-assignable role.".format(role.name), delete_after=self.con.delete_after)
self.con.serverconfig = self.con.load_config()
self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"].append(role.id)
self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"].append(role.id)
self.con.updateconfig()
return await self.bot.say('Role "{}" added'.format(str(role)))

@@ -104,8 +104,8 @@ class selfAssign():
return await self.bot.reply(self.con.no_perms_reponse, delete_after=self.con.delete_after)
else:
self.con.serverconfig = self.con.load_config()
if role.id in self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"]:
self.con.serverconfig[ctx.message.server.id]["self-assign_roles"]["roles"].remove(role.id)
if role.id in self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"]:
self.con.serverconfig[ctx.message.server.id]["selfAssign"]["roles"].remove(role.id)
self.con.updateconfig()
return await self.bot.say('"{}" has been removed from the self-assignable roles.'.format(str(role)))
else:

+ 1
- 1
config/config.json 파일 보기

@@ -1 +1 @@
{"175285455204384768": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self-assign_roles": {"enabled": 0, "roles": []}, "twitch_shilling": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}, "304048071963312130": {"greets": {"enabled": 1, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 1, "goodbye-channel": ""}, "self-assign_roles": {"enabled": 1, "roles": ["307330606348632064", "308083509866659850", "308083509866659850", "308082456743903233"]}, "twitch_shilling": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}}
{"175285455204384768": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}, "304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "", "default-message:": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "selfAssign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}}}

+ 2
- 5
config/config.py 파일 보기

@@ -1,5 +1,4 @@
import json
from pprint import pprint


class Config():
@@ -17,11 +16,11 @@ class Config():
"enabled": 0,
"goodbye-channel": "",
},
"self-assign_roles": {
"selfAssign": {
"enabled": 0,
"roles": []
},
"twitch_shilling": {
"twitch": {
"enabled": 0,
"twitch-channel": "",
"whitelist": {
@@ -31,7 +30,6 @@ class Config():
}
}
}
# Serverconfig is seperate here and shouldnt cause a bug like the cogs o.
self.serverconfig = self.load_config()
self.bot = bot
self.no_perms_reponse = ":no_entry_sign: You do not have permission to use this command."
@@ -52,7 +50,6 @@ class Config():
def updateconfig(self):
with open('config/config.json', 'w') as conf_file:
json.dump(self.serverconfig, conf_file)
pprint(self.serverconfig)

def config_errorcheck(self):
# TODO: Fix so that it checks for problems in children of module settings. i.e children of 'greets'

+ 7
- 5
main.py 파일 보기

@@ -27,7 +27,7 @@ from discord.ext.commands import Bot
from config.config import Config
from cogs import cogs

__version__ = '0.3.0'
__version__ = '0.3.2'

settings = configparser.ConfigParser()
settings.read('config/settings.ini')
@@ -52,12 +52,14 @@ def blacklisted(user):
async def on_ready():
# TODO: First part needs to be moved to wait_until_ready
con.config_errorcheck()
await bot.change_presence(game=discord.Game(name="v0.3.0_Testing"), status=discord.Status.dnd, afk=False)
print("Discord.py version: "+discord.__version__)
print("Client logged in\n")
await bot.change_presence(game=discord.Game(name=__version__), afk=False)
print("Cods loaded:")
for cog in cogs:
bot.load_extension(cog)
print(f"{cog} Cog added")
print(discord.__version__)
print("Client logged in\n")
print("{}".format(cog))
print("")
print("Servers I am currently in:")
for server in bot.servers:
print(server)

Loading…
취소
저장