예제 #1
0
 def test_different_langs(self):
     with patch.dict(
             'pixie.data.STRINGS', {
                 'en': {
                     'test1': 'Test 1',
                     'test2': 'Test 2'
                 },
                 'de': {
                     'test1': '1. Test'
                 }
             }):
         self.assertEqual(messages.get_string('test1', 'de'), '1. Test')
         self.assertEqual(messages.get_string('test2', 'en'), 'Test 2')
         self.assertEqual(messages.get_string('test2', 'de'), 'Test 2')
         self.assertIsNone(messages.get_string('test3'))
예제 #2
0
파일: core.py 프로젝트: unicornsden/pixie
async def on_member_join(member):
    s = servers.get_server_data(member.guild.id)
    channel_id = s.get('join-channel')
    if channel_id is None:
        return
    c = member.guild.get_channel(channel_id)
    await c.send(messages.get_string('join-message', 'de').format(member, c))
예제 #3
0
 def test_unknown_usage(self, message):
     with patch.dict('pixie.data.STRINGS',
                     {'en': {
                         'unknown-args': 'Test {command}'
                     }}):
         message.command = 'test'
         self.assertEqual(messages.get_string('unknown-args'),
                          'Test {command}')
예제 #4
0
파일: dice.py 프로젝트: unicornsden/pixie
def roll_dice(message, dice_count, dice_type, split='d'):
    msg = ''
    roll_sum = 0

    for _ in range(dice_count):
        dice_roll = random.randrange(dice_type) + 1
        roll_sum += dice_roll
        msg += str(dice_roll) + '+'

    msg = msg[:-1]
    if dice_count > 1:
        msg += '=' + str(roll_sum)

    msg = (messages.get_string('dice-roll-1') + str(dice_count) + split +
           str(dice_type) + messages.get_string('dice-roll-2') + msg +
           messages.get_string('dice-roll-3'))

    return messages.send_custom_message(message, msg)
예제 #5
0
파일: users.py 프로젝트: unicornsden/pixie
def set_language(message, lang):
    if not data.exists_lang(lang):
        messages.send_message(message, 'unknown-lang')
        return
    user = get_user(message)
    user.lang = lang
    user.store_settings()
    messages.send_custom_message(message,
                                 messages.get_string('lang-changed') + lang)
예제 #6
0
def set_settings(message, args):
    if not utils.check_permissions(message, admin=True):
        return messages.send_message(message, 'no-permissions')
    set_what = args[0][3:]
    if set_what == 'welcome' and len(message.channel_mentions) != 0:
        channel = message.channel_mentions[0]
        if not isinstance(channel, discord.TextChannel):
            return messages.MessageCode.UNKNOWN_ARGS
        message.server_data.set('welcome-channel', channel.id)
        message.server_data.store_settings()
        messages.send_custom_message(message,
                                     messages.get_string('channel-set').format(
                                         channel, 'welcome channel'),
                                     format_content=False)
        return messages.MessageCode.SENT
    elif set_what == 'welcomeroles' and len(args) > 1:
        roles = args[1:]
        roles_confirmed = list()
        for r in roles:
            for gr in message.guild.roles:
                if r.lower() == gr.name.lower():
                    roles_confirmed.append(gr)
        confirmed_ids = list()
        for r in roles_confirmed:
            confirmed_ids.append(r.id)
        message.server_data.set('welcome-roles', confirmed_ids)
        message.server_data.store_settings()
        if len(confirmed_ids) < 1:
            return messages.MessageCode.UNKNOWN_ARGS
    elif set_what == 'join' and len(message.channel_mentions) != 0:
        channel = message.channel_mentions[0]
        if not isinstance(channel, discord.TextChannel):
            return messages.MessageCode.UNKNOWN_ARGS
        message.server_data.set('join-channel', channel.id)
        message.server_data.store_settings()
        messages.send_custom_message(message,
                                     messages.get_string('channel-set').format(
                                         channel, 'join channel'),
                                     format_content=False)
        return messages.MessageCode.SENT
    else:
        return messages.MessageCode.UNKNOWN_ARGS
예제 #7
0
파일: quotes.py 프로젝트: unicornsden/pixie
def add_quote(quote_list, message):
    if not utils.check_permissions(message):
        messages.send_message(message, 'no-permissions')
    if not os.path.isfile(data.get_path(message, "quotes")):
        f = open(data.get_path(message, "quotes"),'w+')
    else:
        f = open(data.get_path(message, "quotes"),'a+')
    quote = ""
    for s in quote_list:
        quote += s + ' '
    f.write("[quote] " + quote.strip())
    messages.send_custom_message(message, messages.get_string('quotes-added') + quote)
예제 #8
0
파일: core.py 프로젝트: unicornsden/pixie
async def on_member_update(before, after):
    before_roles = before.roles
    after_roles = after.roles
    diff = list(set(after_roles) - set(before_roles))
    if len(diff) < 1:
        return
    s = servers.get_server_data(before.guild.id)
    if str(diff[0].id) in s.get('welcome-roles'):
        channel_id = servers.get_server_data(
            before.guild.id).get('welcome-channel')
        if channel_id is None:
            return
        c = before.guild.get_channel(channel_id)
        await c.send(
            messages.get_string('welcome-message', 'de').format(before, c))
    return
예제 #9
0
 def test_get_string(self):
     with patch.dict('pixie.data.STRINGS', {'en': {'test1': 'Test 1'}}):
         self.assertEqual(messages.get_string('test1'), 'Test 1')
         self.assertEqual(messages.get_string('test2'), None)