-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
managed to cog most admin commands after making a class of the server…
…Data and userData
- Loading branch information
1 parent
ce28b16
commit a1a0a94
Showing
27 changed files
with
1,095 additions
and
1,368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
|
||
data/token.txt | ||
|
||
soup | ||
*.pyc | ||
adventure | ||
selfbot | ||
__pycache__/var.cpython-36.pyc | ||
token.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
Sat Aug 5 22:08:57 2017: Necro#6714 used n!off | ||
Sat Aug 5 22:22:20 2017: Necro#6714 used n!off | ||
Sat Aug 5 22:23:16 2017: Necro#6714 used n!nick <@!172002275412279296> TatsuBot | ||
Sat Aug 5 22:23:33 2017: Necro#6714 used n!reload admin | ||
Sat Aug 5 22:23:39 2017: Necro#6714 used n!nick <@!172002275412279296> TatsuBot | ||
Sat Aug 5 22:24:07 2017: Necro#6714 used n!off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/python3.6 | ||
import discord | ||
from discord.ext import commands | ||
from discord.ext.commands.cooldowns import BucketType | ||
|
||
from rings.botdata.data import Data | ||
|
||
userData = Data.userData | ||
serverData = Data.serverData | ||
|
||
class MiscAdmin(): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
def has_perms(perms_level): | ||
def predicate(cont): | ||
return userData[cont.message.author.id]["perms"][cont.message.server.id] >= perms_level | ||
return commands.check(predicate) | ||
|
||
def is_necro(): | ||
def predicate(cont): | ||
return cont.message.author.id == "241942232867799040" | ||
return commands.check(predicate) | ||
|
||
@commands.command(pass_context = True, hidden=True) | ||
@has_perms(6) | ||
async def add(cont, user : discord.Member, *, equation : str): | ||
"""Does the given pythonic equations on the given user's NecroBot balance. (Permission level required: 6+ (NecroBot Admin))""" | ||
s = str(userData[user.id]["money"]) + equation | ||
try: | ||
operation = simple_eval(s) | ||
userData[user]["money"] = abs(int(operation)) | ||
await bot.say(":atm: | **"+ user.name + "'s** balance is now **"+str(userData[user.id]["money"])+ "** :euro:") | ||
except (NameError,SyntaxError): | ||
await bot.say(":negative_squared_cross_mark: | Operation no recognized.") | ||
|
||
@bot.command(pass_context = True) | ||
async def speak(cont, channel, *, message): | ||
"""Send the given message to the channel mentioned either by id or by mention. Requires the correct permission level on both servers. (Permission level required: 4+ (Server Admin))""" | ||
channel = allmentions(cont, channel)[0] | ||
if userData[cont.message.author.id]["perms"][cont.message.server.id] >= 4 and userData[cont.message.author.id]["perms"][bot.get_channel(ID).server.id] >= 4: | ||
await bot.send_message(bot.get_channel(ID), ":loudspeaker: | " + message) | ||
elif userData[cont.message.author.id]["perms"][bot.get_channel(ID).server.id] < 4: | ||
await bot.say(":negative_squared_cross_mark: | You do not have the required NecroBot permissions on the server you're trying to send the message to.") | ||
else: | ||
await bot.say(":negative_squared_cross_mark: | You do not have the required NecroBot permissions to use this command.") | ||
|
||
@bot.command(pass_context = True, hidden=True) | ||
@has_perms(6) | ||
async def pm(cont, ID, *, message): | ||
"""Sends the given message to the user of the given id. It will then wait 5 minutes for an answer and print it to the channel it was called it. (Permission level required: 6+ (NecroBot Admin))""" | ||
for x in bot.get_all_members(): | ||
if x.id == ID: | ||
user = x | ||
|
||
send = await bot.send_message(user, message + "\n*You have 5 minutes to reply to the message*") | ||
await bot.say("Message sent") | ||
msg = await bot.wait_for_message(author=user, channel=send.channel, timeout=300) | ||
await bot.send_message(cont.message.channel, ":speech_left: | **User: {0.author}** said :**{0.content}**".format(msg)) | ||
|
||
@bot.command(pass_context = True) | ||
@commands.cooldown(1, 10, BucketType.channel) | ||
@has_perms(4) | ||
async def purge(cont, number : int): | ||
"""Removes number of messages from the channel it is called in. That's all it does at the moment but later checks will also be added to allow for more flexible/specific purging (Permission level required: 4+ (Server Admin))""" | ||
await bot.purge_from(cont.message.channel, limit=number+1) | ||
message = await bot.say(":wastebasket: | **" + str(number) + "** messages purged.") | ||
await asyncio.sleep(5) | ||
await bot.delete_message(message) | ||
|
||
@bot.command(pass_context = True) | ||
@has_perms(5) | ||
async def setroles(cont): | ||
"""Sets the NecroBot roles for this server and assigns them to user based on their NecroBot permission level. Permission level required: 5+ (Server Owner))""" | ||
for x in roleList: | ||
if discord.utils.get(cont.message.server.roles, name=x[0]) is None: | ||
new_role = await bot.create_role(cont.message.server, name=x[0], colour=x[1], mentionable=True) | ||
await bot.say("Role " + x[0] + " created") | ||
else: | ||
await bot.say("A role with the name " + x[0] + " already exists.") | ||
await asyncio.sleep(5) | ||
await bot.purge_from(bot.get_channel(cont.message.channel.id), limit=8) | ||
await bot.say("**Roles created**") | ||
|
||
for x in cont.message.server.members: | ||
role = userData[x.id]["perms"][cont.message.server.id]-1 | ||
await bot.add_roles(x, discord.utils.get(cont.message.server.roles, name=roleList[role][0])) | ||
await bot.say("**Roles assigned**") | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(MiscAdmin(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/python3.6 | ||
import ast | ||
import csv | ||
import asyncio | ||
import os | ||
|
||
class Data(): | ||
def __init__(self, serverData, userData, superDuperIgnoreList): | ||
self.serverData = serverData | ||
self.userData = userData | ||
self.superDuperIgnoreList = superDuperIgnoreList | ||
|
||
serverData = dict() | ||
userData = dict() | ||
|
||
with open("C:\\Users\\Clement\\Desktop\\necrobot\\rings\\botdata\\userdata.csv","r") as f: | ||
reader = csv.reader(f) | ||
for row in reader: | ||
permsDict = ast.literal_eval(row[5]) | ||
userData[row[0]] = {"money":int(row[1]),"daily":row[2],"title":row[3],"exp":int(row[4]),"perms":permsDict,"warnings":row[6].split(","),"lastMessage":"","lastMessageTime":0, "locked":""} | ||
|
||
with open("C:\\Users\\Clement\\Desktop\\necrobot\\rings\\botdata\\setting.csv","r") as f: | ||
reader = csv.reader(f) | ||
superDuperIgnoreList = list(next(reader)) | ||
line = next(reader) | ||
for row in reader: | ||
tagsDict = ast.literal_eval(row[10]) | ||
serverData[row[1]] = {"mute":row[2],"automod":row[3],"welcome-channel":row[4], "selfRoles":row[5].split(","),"ignoreCommand":row[6].split(","),"ignoreAutomod":row[7].split(","),"welcome":row[8],"goodbye":row[9],"tags":tagsDict} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
318465643420712962 | ||
Server Name,Server,Mute Role,Automod Channel,Welcome Channel,Self Roles,Automod Ignore,Commands Ignore,Welcome Message,Goodbye Message,Tags | ||
The Land of Shadow,311630847969198082,TimeOut,318828760331845634,318738044515647498,",Evil,Chaotic,Neutral,Lawful,Good",",311789251190587392,312647665395433492,312184736166576129,172002275412279296",",317619283377258497,321305756999745547,312902474753245184,312243558671450113,339330190742126595,172002275412279296,241942232867799040","Hello, {member} and welcome to {server}, don't forget to check out <#311630847969198082>","Bye, we'll miss you {member} :kissing_heart:","{'gao': {'content': 'https://secure.static.tumblr.com/6e33aba611550380136a248fd4f77f1b/afrpxsg/Ryjnnjr7p/tumblr_static_tumblr_static_a80laqb3wj4s084w80c8goc4o_640.gif', 'owner': '241942232867799040'}, 'test': {'content': '*claps feet*', 'owner': '241942232867799040'}, 'test2': {'content': ""This is a really nice server, what do you say it's called? {server.name}? Noice! And you're a very nice user, {member.display_name}. Although this {channel.name} channel really sucks (edited)"", 'owner': '241942232867799040'}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/usr/bin/python3.6 | ||
import discord | ||
from discord.ext.commands import * | ||
import itertools, inspect, re | ||
|
||
class NecroBotHelpFormatter(HelpFormatter): | ||
def __init__(self, show_hidden=False, show_check_failure=True, width=80): | ||
self.width = width | ||
self.show_hidden = show_hidden | ||
self.show_check_failure = show_check_failure | ||
|
||
def get_ending_note(self): | ||
command_name = self.context.invoked_with | ||
return "Type {0}{1} [command] for more info on a command.\n" \ | ||
"Example: `n!help edain` - display help on the edain command \n" \ | ||
"You can also type {0}{1} [category] for more info on a category. \n"\ | ||
"Example: `n!help Animals` - display help on the Animals category".format(self.clean_prefix, command_name) | ||
|
||
def get_ending_note_command(self): | ||
command_name = self.context.invoked_with | ||
return "Type {0}{1} [command] [subcommand] for more info on a command's subcommand.\n" \ | ||
"Example: `n!help settings welcome-channel` - display help on the welcome-channel subcommand of the settings command \n".format(self.clean_prefix, command_name) | ||
|
||
def get_command_signature(self): | ||
"""Retrieves the signature portion of the help page.""" | ||
result = [] | ||
prefix = self.clean_prefix | ||
cmd = self.command | ||
parent = cmd.full_parent_name | ||
if len(cmd.aliases) > 0: | ||
aliases = ' | '.join(cmd.aliases) | ||
fmt = '{0}[{1.name} | {2}]' | ||
if parent: | ||
fmt = '{0}{3} [{1.name} | {2}]' | ||
result.append(fmt.format(prefix, cmd, aliases, parent)) | ||
else: | ||
name = prefix + cmd.name if not parent else prefix + parent + ' ' + cmd.name | ||
result.append(name) | ||
|
||
params = cmd.clean_params | ||
if len(params) > 0: | ||
for name, param in params.items(): | ||
if param.kind == param.VAR_POSITIONAL: | ||
result.append('[{}...]'.format(name)) | ||
else: | ||
result.append('<{}>'.format(name)) | ||
|
||
return ' '.join(result) | ||
|
||
def _add_commands_to_page(self, max_width, commands): | ||
commandList = list() | ||
for name, command in commands: | ||
if name in command.aliases: | ||
# skip aliases | ||
continue | ||
|
||
commandList.append("`{}`".format(name)) | ||
|
||
return " | ".join(commandList) | ||
|
||
def _add_subcommands_to_page(self, max_width, commands): | ||
for name, command in commands: | ||
if name in command.aliases: | ||
# skip aliases | ||
continue | ||
|
||
entry = ' `{0:<{width}}` - {1}'.format(name, command.short_doc, width=max_width) | ||
shortened = self.shorten(entry) | ||
self._paginator.add_line(shortened) | ||
|
||
def format(self): | ||
self._paginator = Paginator(prefix="", suffix="") | ||
if isinstance(self.command, Command): | ||
title = ":information_source: **The `{0}` command** :information_source:".format(self.command) | ||
else: | ||
title = ":information_source: **NecroBot Help Menu** :information_source:" | ||
|
||
|
||
self._paginator.add_line(title) | ||
|
||
# we need a padding of ~80 or so | ||
|
||
description = self.command.description if not self.is_cog() else inspect.getdoc(self.command) | ||
|
||
if description: | ||
# <description> portion | ||
self._paginator.add_line(description, empty=True) | ||
|
||
if isinstance(self.command, Command): | ||
|
||
# <long doc> section | ||
if self.command.help: | ||
self._paginator.add_line(self.command.help, empty=True) | ||
|
||
# <signature portion> | ||
signature = "__Usage__\n" + self.get_command_signature() | ||
self._paginator.add_line(signature, empty=True) | ||
|
||
# end it here if it's just a regular command | ||
if not self.has_subcommands(): | ||
self._paginator.close_page() | ||
return self._paginator.pages | ||
|
||
max_width = self.max_name_size | ||
|
||
def category(tup): | ||
cog = tup[1].cog_name | ||
# we insert the zero width space there to give it approximate | ||
# last place sorting position. | ||
return "**" + cog + '** - ' if cog is not None else '\u200b**No Category** - ' | ||
|
||
if self.is_bot(): | ||
data = sorted(self.filter_command_list(), key=category) | ||
counter = 0 | ||
for category, commands in itertools.groupby(data, key=category): | ||
# there simply is no prettier way of doing this. | ||
counter += 1 | ||
commands = list(commands) | ||
if len(commands) > 0: | ||
self._paginator.add_line(str(counter) + ". " + category + self._add_commands_to_page(max_width, commands)) | ||
|
||
# add the ending note for general help | ||
ending_note = self.get_ending_note() | ||
|
||
else: | ||
self._paginator.add_line('Sub-commands:') | ||
self._add_subcommands_to_page(max_width, self.filter_command_list()) | ||
|
||
# add the ending note for command pages | ||
ending_note = self.get_ending_note_command() | ||
|
||
self._paginator.add_line() | ||
self._paginator.add_line(ending_note) | ||
return self._paginator.pages |
Oops, something went wrong.