Esempio n. 1
0

async def global_delete_data(Demobot, msg, reg):
    if msg.author.id == (await get_owner(Demobot)).id:
        keys = reg.group('path').split()
        if isinstance(nested_get(*keys[:-1]), dict):
            nested_pop(*keys)
        elif isinstance(nested_get(*keys[:-1]), list):
            nested_remove(keys[-1], *keys[:-1])
        await save(None, None, None, overrideperms=True)


async def find(Demobot, msg, reg):
    if reg.group('key') == '*':
        await Demobot.send_message(
            msg.channel,
            '`' + str(list(server_data[msg.server.id].keys())) + '`')
        return
    await Demobot.send_message(
        msg.channel, '```xml\n' +
        pformat(server_data[msg.server.id][reg.group('key')]) + '```')


add_message_handler(save, r'save\Z')
add_message_handler(getData, r'getdata\Z')
add_message_handler(delete_data, r'(?:remove|delete) (?P<path>.*)\Z')
add_message_handler(global_delete_data,
                    r'global (?:remove|delete) (?P<path>.*)\Z')

add_message_handler(find, r'sub (?P<key>.*)\Z')
Esempio n. 2
0
        newm = await Demobot.send_message(propchan, '\u200D')
        content = "make " + reg.group("user") + " a " + role.mention + "."
        em = Embed(title=type.title() + ' Proposal',
                   description=('ID: %s\n\n%s' % (newm.id, content)),
                   colour=nested_get(msg.server.id, "roles",
                                     "representative").colour)
        newm = await Demobot.edit_message(newm,
                                          nested_get(msg.server.id, "roles",
                                                     "representative").mention,
                                          embed=em)

        propobj = Nomination(newm, type, content, msg.author, msg.mentions[0],
                             role)
        nested_set(propobj, msg.server.id, 'messages', 'proposals', newm.id)
        await Demobot.add_reaction(newm, "­ЪЉЇ")
        await Demobot.add_reaction(newm, "­ЪЉј")
        await Demobot.add_reaction(newm, "­Ъци")
        await save(None, None, None, overrideperms=True)
    else:
        await Demobot.send_message(msg.channel, "You are not leader!")


add_message_handler(
    running,
    r'I\s*(?:(?:want|would\s*like)\s*to\s*run|am\s*running)\s*for\s*(?P<pos>.*?)\Z'
)
add_message_handler(
    nominate,
    r'(?:I )?(?:want to )?nominate (?P<user><@!?(?P<userid>[0-9]+)>) for (?P<pos>.*)\Z'
)
Esempio n. 3
0
            "rewrite": "override"
        }
        if reg.group("type"):
            if reg.group("type") not in aliases:
                return
            type = aliases[reg.group("type").lower()]
        else:
            type = "rule"
        propchan = nested_get(msg.server.id, "channels", 'proposals')
        newm = await Demobot.send_message(propchan, '\u200D')
        em = Embed(
            title=type.title() + ' Proposal',
            description=('ID: %s\n\n%s' % (newm.id, reg.group("content"))),
            colour=nested_get(msg.server.id, "roles", "representative").colour)
        newm = await Demobot.edit_message(newm,
                                          nested_get(msg.server.id, "roles",
                                                     "representative").mention,
                                          embed=em)

        propobj = Proposal(newm, type, reg.group('content'), msg.author)
        nested_set(propobj, msg.server.id, 'messages', 'proposals', newm.id)
        await Demobot.add_reaction(newm, "­ЪЉЇ")
        await Demobot.add_reaction(newm, "­ЪЉј")
        await Demobot.add_reaction(newm, "­Ъци")
        await save(None, None, None, overrideperms=True)


add_message_handler(
    propose, r'(?P<type>.*?)\s*prop(?:osal)?:\s*(?P<content>(?:.|\s)*?)\Z')
add_message_handler(cancel, r'\s*cancel\s*prop\s*(?P<num>[0-9]*)\Z')
Esempio n. 4
0
            'politics': 'politics',
            'rules': 'rules',
            'rule': 'rules',
            'law': 'rules',
            'laws': 'rules',
            'passed proposals': 'rules',
            'enforcer todo': 'enf-todo',
            'todo': 'enf-todo',
            'election': 'elections'
        }
        if reg.group('name') not in aliases:
            return
        nested_set(Demobot.get_channel(reg.group('channelid')), msg.server.id,
                   "channels", aliases[reg.group('name').lower()])
        await Demobot.send_message(
            msg.channel, 'The ' + aliases[reg.group('name').lower()] +
            ' channel for this server is now set to ' +
            nested_get(msg.server.id, "channels",
                       aliases[reg.group('name').lower()]).mention + '.')
        await save(None, None, None, overrideperms=True)


add_message_handler(
    channel,
    r'make\s*(?P<channel><#(?P<channelid>[0-9]*)>)\s*(?:an?|the)\s*(?P<name>.*?)\s*channel$'
)
add_message_handler(
    role,
    r'make\s*(?P<role><@&(?P<roleid>[0-9]*)>|@everyone)\s*(?:an?|the)\s*(?P<name>.*?)\s*role$'
)
Esempio n. 5
0
        await imprison(Demobot, msg.mentions[0], reasons)
    else:
        await Demobot.send_message(msg.channel, "You are not an enforcer!")

async def unimprison(Demobot, user):
    await Demobot.remove_roles(user, nested_get(user.server.id, "roles", "prisoner"))
    await Demobot.send_message(user, "You have been released from prison.")

async def enfunimprison(Demobot, msg, reg):
    if nested_get(msg.server.id, "roles", "enforcer") in msg.author.roles:
        await unimprison(Demobot, msg.mentions[0])
    else:
        await Demobot.send_message(msg.channel, "You are not an enforcer!")

async def impeach(Demobot, user):
    await Demobot.remove_roles(user, *[v for k, v in nested_get(user.server.id, "roles").items() if k not in ['prisoner', 'citizen']])

async def enfimpeach(Demobot, msg, reg):
    if nested_get(msg.server.id, "roles", "enforcer") in msg.author.roles:
        reasons = reg.group('reasons')
        if not reasons:
            reasons = "for no reason"
        await Demobot.send_message(msg.channel, msg.mentions[0].mention+' has been impeached '+reasons)
        await impeach(Demobot, msg.mentions[0])
    else:
        await Demobot.send_message(msg.channel, "You are not an enforcer!")

add_message_handler(enfimpeach, r'impeach (?P<user><@!?(?P<userid>[0-9]+)>) (?P<reasons>.*)?\Z')
add_message_handler(enfimprison, r'(?:imprison|jail) (?P<user><@!?(?P<userid>[0-9]+)>) (?P<reasons>.*)?\Z')
add_message_handler(enfunimprison, r'(?:unimprison|release) (?P<user><@!?(?P<userid>[0-9]+)>)\Z')
Esempio n. 6
0
                msg.server,
                name="admin",
                permissions=msg.server.get_member(
                    Demobot.user.id).server_permissions)
            nested_set(r, msg.server.id, "roles", "admin")
        await Demobot.move_role(
            msg.server, r,
            msg.server.get_member(Demobot.user.id).top_role.position - 1)
        await Demobot.add_roles(msg.mentions[0], r)
        await save(None, None, None, overrideperms=True)


async def removeAdmin(Demobot, msg, reg):
    await Demobot.remove_roles(msg.mentions[0],
                               nested_get(msg.server.id, 'roles', 'admin'))


add_message_handler(save, r'save\Z')
add_message_handler(getData, r'getdata\Z')
add_message_handler(delete_data, r'(?:remove|delete) (?P<path>.*)\Z')
add_message_handler(global_delete_data,
                    r'global (?:remove|delete) (?P<path>.*)\Z')
add_message_handler(makeMod, r'make (?P<user><@!?(?P<userid>[0-9]+)>) mod\Z')
add_message_handler(removeMod, r'del (?P<user><@!?(?P<userid>[0-9]+)>) mod\Z')
add_message_handler(makeAdmin,
                    r'make (?P<user><@!?(?P<userid>[0-9]+)>) admin\Z')
add_message_handler(removeAdmin,
                    r'del (?P<user><@!?(?P<userid>[0-9]+)>) admin\Z')

add_message_handler(find, r'sub (?P<key>.*)\Z')
Esempio n. 7
0
            'pres': 'leader',
            'president': 'leader',
            'leader': 'leader'
        }
        if reg.group('pos') not in aliases:
            return
        dmm = await Demobot.send_message(
            msg.author,
            "DM me a description for " + aliases[reg.group('pos')] + ".")
        m = await Demobot.wait_for_message(timeout=600,
                                           author=msg.author,
                                           channel=dmm.channel)
        if not m:
            m = "*No description given*"
        else:
            m = m.content
        nested_pop(msg.server.id, 'elections', aliases[reg.group('pos')],
                   msg.author.id)
        nested_set(Candidate(m, msg.author.id), msg.server.id, 'elections',
                   aliases[reg.group('pos')], msg.author.id)
        await Demobot.send_message(msg.author, "You are now running.")
        await save(None, None, None, overrideperms=True)
    else:
        await Demobot.send_message(msg.channel, "You must be a citizen!")


add_message_handler(
    running,
    r'I\s*(?:(?:want|would\s*like)\s*to\s*run|am\s*running)\s*for\s*(?P<pos>.*?)\Z'
)