Ejemplo n.º 1
0
    def on_pubmsg(self, mcid, text):
        print('[CHAT]', '<%s>' % mcid, text)

        parts = text.split('--')
        for i in range(1, len(parts), 2):
            if parts[i].startswith('-'):
                parts[i], _ = self.codec3.decode(parts[i][1:])
            else:
                parts[i], _ = self.codec2.decode(parts[i])
        converted = ''.join(parts)

        if converted.strip():
            # 명령처럼 보이면 그걸 우선시함
            if converted.startswith('!'):
                args = converted[1:].split()
                if args:
                    if cmd(True, mcid, args[0], args[1:]): return True

            # IRC와 (한글 변환이 이루어졌을 경우) 마인크래프트에 재출력
            if converted != text:
                bot.send_to_mc('tellraw', '@a', {'text': '', 'extra': [
                    {'text': '<%s> ' % mcid, 'color': 'gold'},
                    {'text': converted}
                ]})
            say('<%s> %s' % (to_ircnick(mcid) or mcid, converted))
        return True
Ejemplo n.º 2
0
def line(command, source, param, message):
    if command == 'join':
        nick = getnick(source)
        if nick: bot.send_to_mc('tellraw', '@a', {'text': '', 'extra': [
            {'text': '[IRC] %s님이 입장하셨습니다.' % nick, 'color': 'gold'}
        ]})
    elif command == 'part':
        nick = getnick(source)
        if nick: bot.send_to_mc('tellraw', '@a', {'text': '', 'extra': [
            {'text': '[IRC] %s님이 나가셨습니다.' % nick, 'color': 'gold'}
        ]})
Ejemplo n.º 3
0
def msg(channel, source, msg):
    wascmd = False
    if msg.startswith('!'):
        args = msg[1:].split()
        if args:
            wascmd = cmd(False, getnick(source), args[0], args[1:])

    if not wascmd:
        nick = getnick(source)
        if nick and '\001' not in msg: # no CTCP yet
            bot.send_to_mc('tellraw', '@a', {'text': '', 'extra': [
                {'text': '[IRC] ', 'color': 'gold'},
                {'text': '<%s> %s' % (nick, msg.replace('\247', '')), 'color': 'white'}
            ]})
Ejemplo n.º 4
0
 def sayboth(msg, title, link):
     say('## %s: \002%s\002 @ %s' % (msg, title, link))
     bot.send_to_mc('say', '\2472## %s: \247a%s\2472 @ %s' % (msg, title, link))
Ejemplo n.º 5
0
 def on_login(self, mcid, ip, entityid, coord):
     for msg in config.welcome_messages:
         bot.send_to_mc('tellraw', mcid, msg)
     say('*** %s님이 마인크래프트에 접속하셨습니다.' % (to_ircnick(mcid) or mcid))
     with transaction():
         DB.execute("update users set last_login=datetime('now') where mcid=?;", (mcid,))
Ejemplo n.º 6
0
def cmd(ismc, nick, cmd, args):
    reply = mcsay if ismc else say
    cmd = cmd.lower()

    if cmd == 'help' or cmd == 'commands':
        reply('명령 목록: !commands, !players (!p), !who (!w), !set, !time (!t), !kit')
        return True

    if cmd == 'players' or cmd == 'p' or cmd == 'ㅔ':
        if ismc:
            reply('%s, 이 명령은 마인크래프트 안에서는 사용할 수 없습니다.' % nick)
        else:
            bot.is_players = True
            bot.send_to_mc('list')
        return True

    if cmd == 'whois' or cmd == 'who' or cmd == 'w' or cmd == 'ㅈ':
        if len(args) != 1:
            reply('사용법: !who <마인크래프트 아이디 또는 IRC 닉>')
            return True

        escaped = escape_for_like(args[0], '|')
        c = DB.execute('select * from users where mcid like ? escape ?;', (escaped, '|'))
        row = c.fetchone()
        if not row:
            c = DB.execute('select * from users where ircnick like ? escape ?;', (escaped, '|'))
            row = c.fetchone()
            if not row:
                reply('%s, 해당하는 사용자가 없습니다.' % nick)
                return True

        reply('사용자 정보: 마인크래프트 %s' % bold(ismc, row['mcid']) +
              (' / IRC %s' % bold(ismc, row['ircnick']) if row['ircnick'] else '') +
              (' / 총 플레이 시간 %s' % bold(ismc, readable_timedelta(row['playtime']))) +
              (' | 소개: %s' % row['intro'] if row['intro'] else ''))
        return True

    if cmd == 'set':
        key = ''
        if len(args) >= 2: key = args[0]

        if key == 'ircnick':
            if ismc:
                with transaction():
                    u = get_user(ismc, nick, create=True)
                    if u: DB.execute('update users set ircnick=? where mcid=?;', (args[1], u['mcid']))
                reply('%s, IRC 닉을 설정했습니다.' % nick)
            else:
                reply('%s, 이 명령은 마인크래프트 밖에서는 사용할 수 없습니다.' % nick)
        elif key == 'intro':
            intro = ' '.join(args[1:]) # 공백따위...
            with transaction():
                u = get_user(ismc, nick, create=True)
                if u: DB.execute('update users set intro=? where mcid=?;', (intro, u['mcid']))
            if u:
                reply('%s, 자기 소개를 설정했습니다.' % nick)
            else:
                reply('%s, 이 명령을 처음 사용할 때는 마인크래프트 안에서 사용해야 합니다.' % nick)
        else:
            reply('사용법: !set {ircnick|intro} <값>')

        return True

    if cmd == 'time' or cmd == 't' or cmd == 'ㅅ':
        leveldat = mcutil.parse_level_dat(bot.WORLDPATH)
        delta = leveldat['*LastUpdatedBefore']
        # 6000이 실제로는 정오니까 보정이 필요. 그리고 날짜는 1일째부터 시작하므로 그것도 보정.
        days, timeofday = divmod(leveldat['DayTime'] + int(delta * 20) + 30000, 24000)
        minutes = timeofday * 1440 / 24000
        reply('%d일째 %02d:%02d (%d초 전 갱신)' % (days, minutes/60, minutes%60, delta))
        return True

    if cmd == 'kit':
        if not ismc:
            reply('%s, 이 명령은 마인크래프트 밖에서는 사용할 수 없습니다.' % nick)
        else:
            u = get_user(ismc, nick)
            if not u or u['status'] < STATUS_WHITELISTED:
                reply('%s, !set 명령을 한 번 이상 써야 합니다.' % nick)
            elif u['status'] == STATUS_KITRECEIVED:
                reply('%s, 이미 기본 아이템을 받았으면 다시 받을 수 없습니다. 필요하다면 관리자를 요청하세요.' % nick)
            else:
                bot.send_to_mc('give', u['mcid'], '256') # iron shovel
                bot.send_to_mc('give', u['mcid'], '257') # iron pickaxe
                bot.send_to_mc('give', u['mcid'], '258') # iron axe
                bot.send_to_mc('give', u['mcid'], '292') # iron hoe
                bot.send_to_mc('give', u['mcid'], '267') # iron sword
                bot.send_to_mc('give', u['mcid'], '50', '64') # 64x torch
                bot.send_to_mc('give', u['mcid'], '297', '64') # 64x bread
                bot.send_to_mc('give', u['mcid'], '328') # minecart
                bot.send_to_mc('give', u['mcid'], '355') # bed
                with transaction():
                    DB.execute('update users set status=? where mcid=?;', (STATUS_KITRECEIVED, u['mcid']))
                reply('%s, 기본 아이템을 보내 드렸습니다. 만약 이상이 있다면 관리자에게 요청해 주세요.' % nick)
        return True
Ejemplo n.º 7
0
def mcsay(s):
    if s:
        if isinstance(s, dict):
            bot.send_to_mc('tellraw', "@a", s)
        else:
            bot.send_to_mc('tellraw', "@a", {"text": "", "extra": [{"text": s}]})