Initial Upload of Geeksbot Files

This commit is contained in:
Dusty.P
2018-04-13 23:10:36 -08:00
parent eb4110e1e6
commit 465e22163f
41 changed files with 2999 additions and 0 deletions
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+64
View File
@@ -0,0 +1,64 @@
import discord, json, asyncio
from . import utils
owner_id = 351794468870946827
def check_admin_role(bot, ctx, member):
admin_roles = json.loads(bot.con.one(f"select admin_roles from guild_config where guild_id = {ctx.guild.id}"))
for role in admin_roles:
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in member.roles:
return True
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.con.one(f"select rcon_admin_roles from guild_config where guild_id = {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.con.one(f"select admin_roles from guild_config where guild_id = {ctx.guild.id}"))
for role in admin_roles:
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in ctx.message.author.roles:
return True
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
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.con.one(f"select rcon_admin_roles from guild_config where guild_id = {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
return ctx.message.author.id == ctx.guild.owner.id or ctx.message.author.id == owner_id
def is_restricted_chan(ctx):
if ctx.guild:
if ctx.channel.overwrites_for(ctx.guild.default_role).read_messages == False:
return True
return False
return False
async def is_spam(bot, ctx):
max_rep = 5
rep_time = 20
spam_rep = 5
spam_time = 3
spam_check = 0
msg_check = 0
for msg in bot.recent_msgs[ctx.guild.id]:
if msg['author'] == ctx.author:
if msg['time'] > ctx.message.created_at.timestamp() - spam_time:
spam_check += 1
if msg['content'].lower() == ctx.content.lower() and msg['time'] > ctx.message.created_at.timestamp() - rep_time:
msg_check += 1
if spam_check == spam_rep - 1 or msg_check == max_rep - 1:
await utils.mute(bot, ctx, admin=1, member=ctx.author.id)
return True
return False
+87
View File
@@ -0,0 +1,87 @@
from io import StringIO
import sys, asyncio
from discord.ext.commands.formatter import Paginator
from . import checks
class Capturing(list):
def __enter__(self):
self._stdout = sys.stdout
sys.stdout = self._stringio = StringIO()
return self
def __exit__(self, *args):
self.extend(self._stringio.getvalue().splitlines())
del self._stringio # free up some memory
sys.stdout = self._stdout
async def mute(bot, ctx, admin=0, member_id=None):
mute_role = self.bot.con.one(f'select muted_role from guild_config where guild_id = {ctx.guild.id}')
if muted_role:
if admin or checks.is_admin(bot, ctx):
if ctx.guild.me.guild_permissions.manage_roles:
if member:
ctx.guild.get_member(member_id).edit(roles=[discord.utils.get(ctx.guild.roles, id=mute_role)])
def to_list_of_str(items, out:list=[], level=1, recurse=0):
def rec_loop(item, key, out, level):
quote = '"'
if type(item) == list:
out.append(f'{" "*level}{quote+key+quote+": " if key else ""}[')
new_level = level + 1
out = to_list_of_str(item, out, new_level, 1)
out.append(f'{" "*level}]')
elif type(item) == dict:
out.append(f'{" "*level}{quote+key+quote+": " if key else ""}{{')
new_level = level + 1
out = to_list_of_str(item, out, new_level, 1)
out.append(f'{" "*level}}}')
else:
out.append(f'{" "*level}{quote+key+quote+": " if key else ""}{repr(item)},')
if type(items) == list:
if not recurse:
out = []
out.append('[')
for item in items:
rec_loop(item, None, out, level)
if not recurse:
out.append(']')
elif type(items) == dict:
if not recurse:
out = []
out.append('{')
for key in items:
rec_loop(items[key], key, out, level)
if not recurse:
out.append('}')
return out
def paginate(text):
data = []
paginator = Paginator(prefix='```py')
if type(text) == list:
data = to_list_of_str(text)
elif type(text) == dict:
data = to_list_of_str(text)
else:
data = str(text).split('\n')
for line in data:
if len(line) > 1900:
n = 1900
for l in [line[i:i+n] for i in range(0, len(line), n)]:
paginator.add_line(l)
else:
paginator.add_line(line)
return paginator.pages
async def run_command(*args):
# Create subprocess
process = await asyncio.create_subprocess_exec(
*args,
# stdout must a pipe to be accessible as process.stdout
stdout=asyncio.subprocess.PIPE)
# Wait for the subprocess to finish
stdout, stderr = await process.communicate()
# Return stdout
return stdout.decode().strip()