def main(): if len(sys.argv) < 2: print("usage: ./initrights.py [snowflake]") subject = sys.argv[1] db = auth.RightsDB("rights.db") db.write_permission(auth.SCOPE_USER, subject, auth.declare_right("MANAGE_PERMISSIONS"), 1)
async def grant(context, message, content, check_flag=1): args = content.split() if len(args) < 2: return await context.reply("You must provide a target and a list of rights.") target = args.pop(0) scope = None subject = None if target == "'server": scope = auth.SCOPE_SERVER subject = message.server.id elif target.startswith("~"): scope = SCOPE_CHAR.get(target[1], None) if scope is None: return await context.reply("The scope is invalid.") subject = target[2:] else: match = mention_regex.match(target) if match: scope = auth.SCOPE_USER if match.group(1) == "@" else auth.SCOPE_CHANNEL subject = match.group(2) if not (scope and subject): return await context.reply("Grant target invalid, nya.") for flagname in args: if flagname.startswith("-"): have = 0 flagname = flagname[1:] else: have = 1 if check_flag and flagname not in auth.KNOWN_PERMISSION_FLAGS: return await context.reply("Undeclared right, {0}.".format( flagname, content)) context.of("auth").write_permission(scope, subject, auth.declare_right(flagname), have) try: await context.client.add_reaction(message, "\u2705") except discord.errors.Forbidden: await context.reply("\u2705", mention=1)
import loader import discord import sqlite3 import auth P_SELFROLE_ADMIN = auth.declare_right("SELFROLE_ADMIN") P_SELFROLE_USE = auth.declare_right("SELFROLE_USE") class RoleNotFound(Exception): pass @loader.context_class class SelfRoleDB(object): def __init__(self): connection = sqlite3.connect("selfrole.db") connection.execute("""CREATE TABLE IF NOT EXISTS selfroles_v1 ( server TEXT, name TEXT, role_id TEXT, mutual_exclusion_group INT ) """) connection.commit() self.connection = connection def add_sar(self, server, role_id, name): self.connection.execute("INSERT INTO selfroles_v1 VALUES (?, ?, ?, ?)",
import json import discord import sqlite3 import time import sys import pytz import asyncio from datetime import datetime, timedelta from collections import namedtuple import loader import auth JST = pytz.timezone("Asia/Tokyo") P_DERESUTE_PUBLIC = auth.declare_right("DERESUTE_PUBLIC") P_DERESUTE_NOISY = auth.declare_right("DERESUTE_NOISY") P_DERESUTE_CUTOFFS = auth.declare_right("DERESUTE_CUTOFFS") P_DERESUTE_ADMIN = auth.declare_right("DERESUTE_ADMIN") class IDAlreadyExistsError(Exception): pass class NameNeedsOneOrMoreNonNumbersError(Exception): pass class IDNotDeletedError(Exception): pass
import loader import auth import shlex import re import discord P_MANAGE_PERMISSIONS = auth.declare_right("MANAGE_PERMISSIONS") SCOPE_CHAR = { "u": auth.SCOPE_USER, "r": auth.SCOPE_ROLE, "c": auth.SCOPE_CHANNEL, "s": auth.SCOPE_SERVER, } mention_regex = re.compile("<(@|#)!?([0-9]+)>") @loader.command("grant", description="Give flags to a specific user, role, or the entire server.", synopsis="['server | #channel | @user] flag ...", examples=["'server MANAGE_PERMISSIONS", "@Miku-nya#7061 DEBUG_COMMAND"]) @auth.requires_right(P_MANAGE_PERMISSIONS) async def grant(context, message, content, check_flag=1): args = content.split() if len(args) < 2: return await context.reply("You must provide a target and a list of rights.") target = args.pop(0) scope = None subject = None
import loader import config import sqlite3 import auth P_MANAGE_QUOTE = auth.declare_right("MANAGE_QUOTE") P_USE_QUOTE = auth.declare_right("USE_QUOTE") class QuoteAlreadyExistsError(Exception): pass @loader.context_class class QuoteDB(object): def __init__(self): connection = sqlite3.connect("quotes.db") connection.execute("""CREATE TABLE IF NOT EXISTS quotes_v1 ( _command TEXT, _originator TEXT, _response TEXT ) """) connection.commit() self.connection = connection self.managed_command_names = set() async def init_with_context(self, bot): for name in self.quote_names(): self.guard_add_command(name)
self.snapshot[name] = hash.hexdigest() def has_file_changed(self, filename): fp = os.path.join(self.root, filename) hash = hashlib.sha256() with open(fp, "rb") as srcfile: hash.update(srcfile.read()) if hash.hexdigest() != self.snapshot[filename]: return 1 else: return 0 P_SELF_UPDATE = auth.declare_right("SELF_UPDATE") ESSENTIAL_FILES = ["auth.py", "bot.py", "command_object.py", "config.py", "error_reporting.py", "loader.py"] @loader.command("sync", description="Update from a configured git repository.") @auth.requires_right(P_SELF_UPDATE) async def sync_command(context, message, content): if not content: content = config.get("git_sync.default_pull_args", "origin master") code_dir = os.path.dirname(sys.modules["__main__"].__file__) ds = DirectorySnapshot(code_dir) git = sh.git.bake("--git-dir=" + os.path.join(code_dir, ".git"), "--work-tree=" + code_dir)
import loader import auth P_INVITE = auth.declare_right("INVITE") @loader.command("joinserver", description="Join the server from an instant invite link.", synopsis="[link]") @auth.requires_right(P_INVITE) async def joinserver(context, message, content): await context.client.accept_invite(content) try: await context.client.add_reaction(message, "\u2705") except discord.errors.Forbidden: await context.reply("\u2705")
import lldata import discord import random import loader import auth P_SIF_PUBLIC = auth.declare_right("SIF_PUBLIC") sif = loader.register_command("sif", description="Umbrella command for SIF.") @sif.subcommand("cutoffs", description="Retrieve current event cutoffs.", synopsis="[en | jp]") @auth.requires_right(P_SIF_PUBLIC) async def sif_cutoffs(context, message, text): events = await lldata.llsif_fetch_eventinfo() if text == "en": sid = "EN" else: sid = "JP" evt = events[sid] cutoff = await lldata.llsif_fetch_real_cutoffs(sid, evt.id) embed = embed_from_cutoff(evt, cutoff) embed.url = "http://llsif.net/index.html?s={0}&e={1}".format(sid, evt.id) embed.set_footer(text="llsif.net")
import loader import auth import traceback import sys import config import json import discord import os import binascii P_MANAGE_CONFIG = auth.declare_right("MANAGE_CONFIG") P_MANAGE_MODULES = auth.declare_right("MANAGE_MODULES") P_EVAL_CODE = auth.declare_right("EVAL_CODE") mod = loader.register_command("mod", "m", description="Load, reload, and unload command modules.") @mod.subcommand("reload", description="Reload a module.") @auth.requires_right(P_MANAGE_MODULES) async def reload_mod(context, message, content): fq = loader.fq_from_leaf(content) if fq not in sys.modules: return await context.reply("It's not loaded, nya.") bot = context.of("discordbot") mod = sys.modules[fq] loader.unload_module(content) await bot.uninit_module(mod)