コード例 #1
0
ファイル: commands.py プロジェクト: mekolat/manachat
def send_whisper(_, arg):
    '''Send whisper to player
/w "Player Name" Message...
/w NameWithourSpaces Message'''
    nick, message = parse_player_name(arg)
    if len(nick) > 0 and len(message) > 0:
        chat.send_whisper(nick, message)
コード例 #2
0
def send_whisper(_, arg):
    '''Send whisper to player
/w "Player Name" Message...
/w NameWithourSpaces Message'''
    nick, message = parse_player_name(arg)
    if len(nick) > 0 and len(message) > 0:
        chat.send_whisper(nick, message)
コード例 #3
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def globalmsg(nick, msg):
    if not msg:
        send_whisper(nick, "Usage: !global Message")
        return

    online = online_users.online_users
    for prow in db.all_players_any_guild():
        pname = prow[0]
        if pname in online:
            send_whisper(pname, msg)
コード例 #4
0
def globalmsg(nick, msg):
    if not msg:
        send_whisper(nick, "Usage: !global Message")
        return

    online = online_users.online_users
    for prow in db.all_players_any_guild():
        pname = prow[0]
        if pname in online:
            send_whisper(pname, msg)
コード例 #5
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def broadcast(nick, msg, exclude_nick=False):
    """
    Broadcast message for all players that belong the same guild as nick.
    """
    n = 0
    for prec in db.all_players_same_guild(nick):
        if exclude_nick and prec[0] == nick:
            continue
        n += 1
        send_whisper(prec[0], '{} : {}'.format(nick, msg))

    if n == 0:
        send_whisper(nick, "You don't belong to any guild")
コード例 #6
0
def broadcast(nick, msg, exclude_nick=False):
    """
    Broadcast message for all players that belong the same guild as nick.
    """
    n = 0
    for prec in db.all_players_same_guild(nick):
        if exclude_nick and prec[0] == nick:
            continue
        n += 1
        send_whisper(prec[0], '{} : {}'.format(nick, msg))

    if n == 0:
        send_whisper(nick, "You don't belong to any guild")
コード例 #7
0
def listonline(nick, _):
    curr_msg = ''
    online = online_users.online_users

    for prow in db.all_players_same_guild(nick):
        p = prow[0]
        if p in online:
            if len(curr_msg + ', ' + p) > max_msg_len:
                send_whisper(nick, curr_msg)
                curr_msg = p
            else:
                curr_msg = curr_msg + ', ' + p

    send_whisper(nick, curr_msg)
コード例 #8
0
def setaccess(nick, params):
    try:
        si = params.index(" ")
        lvl = int(params[:si])
        player = params[si + 1:]
        if len(player) < 4:
            raise ValueError
    except ValueError:
        send_whisper(nick, "Usage: !setaccess Level Player")
        return

    gid, guild_name, access = db.player_info(nick)
    gidp, _, accessp = db.player_info(player)

    if gid != gidp:
        send_whisper(nick,
                     '{} is not in your guild "{}"'.format(player, guild_name))
        return

    if access <= accessp:
        send_whisper(nick, "You cannot set access level for {}".format(player))
        return

    db.player_set_access(player, lvl)
    send_whisper(nick, "Player: {}, access level: {}".format(player, lvl))
コード例 #9
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def listonline(nick, _):
    curr_msg = ''
    online = online_users.online_users

    for prow in db.all_players_same_guild(nick):
        p = prow[0]
        if p in online:
            if len(curr_msg + ', ' + p) > max_msg_len:
                send_whisper(nick, curr_msg)
                curr_msg = p
            else:
                curr_msg = curr_msg + ', ' + p

    send_whisper(nick, curr_msg)
コード例 #10
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def online_list_update(curr, prev):
    for p in curr - prev:
        ginfo = db.player_info(p)
        if ginfo is not None:
            if ginfo[0] is not None:
                allp = set(db.all_players_same_guild(p))
                n = len(allp.intersection(curr))
                send_whisper(p,
                    'Welcome to {}! ({} Members are online)'.format(
                        ginfo[1], n))
                broadcast(p, '{} is now Online'.format(p), True)

    for p in prev - curr:
        broadcast(p, '{} is now Offline'.format(p), True)
コード例 #11
0
def online_list_update(curr, prev):
    for p in curr - prev:
        ginfo = db.player_info(p)
        if ginfo is not None:
            if ginfo[0] is not None:
                allp = set(db.all_players_same_guild(p))
                n = len(allp.intersection(curr))
                send_whisper(
                    p, 'Welcome to {}! ({} Members are online)'.format(
                        ginfo[1], n))
                broadcast(p, '{} is now Online'.format(p), True)

    for p in prev - curr:
        broadcast(p, '{} is now Offline'.format(p), True)
コード例 #12
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def setaccess(nick, params):
    try:
        si = params.index(" ")
        lvl = int(params[:si])
        player = params[si + 1:]
        if len(player) < 4:
            raise ValueError
    except ValueError:
        send_whisper(nick, "Usage: !setaccess Level Player")
        return

    gid, guild_name, access = db.player_info(nick)
    gidp, _, accessp = db.player_info(player)

    if gid != gidp:
        send_whisper(nick, '{} is not in your guild "{}"'.format(
            player, guild_name))
        return

    if access <= accessp:
        send_whisper(nick, "You cannot set access level for {}".format(
            player))
        return

    db.player_set_access(player, lvl)
    send_whisper(nick, "Player: {}, access level: {}".format(
        player, lvl))
コード例 #13
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def exec_command(nick, cmdline):
    end = cmdline.find(" ")
    if end < 0:
        cmd = cmdline[1:]
        arg = ""
    else:
        cmd = cmdline[1:end]
        arg = cmdline[end + 1:]

    if cmd in commands:
        lvl, func, _ = commands[cmd]
        access = db.player_get_access(nick)

        if access < lvl:
            send_whisper(nick, 'That command is fobidden for you!')
        else:
            func(nick, arg)

    else:
        send_whisper(nick, 'Command !{} not found. Try !help'.format(cmd))
コード例 #14
0
def exec_command(nick, cmdline):
    end = cmdline.find(" ")
    if end < 0:
        cmd = cmdline[1:]
        arg = ""
    else:
        cmd = cmdline[1:end]
        arg = cmdline[end + 1:]

    if cmd in commands:
        lvl, func, _ = commands[cmd]
        access = db.player_get_access(nick)

        if access < lvl:
            send_whisper(nick, 'That command is fobidden for you!')
        else:
            func(nick, arg)

    else:
        send_whisper(nick, 'Command !{} not found. Try !help'.format(cmd))
コード例 #15
0
def showhelp(nick, _):
    access = db.player_get_access(nick)
    curr_line = ''

    for cmd, (lvl, _, hlp) in commands.iteritems():
        if access < lvl:
            continue

        if hlp[0] == '+':
            help_s = '!' + cmd + ' ' + hlp[1:]
        else:
            help_s = '!' + cmd + ' -- ' + hlp

        if len(curr_line + '; ' + help_s) > max_msg_len:
            send_whisper(nick, curr_line)
            curr_line = help_s
        else:
            curr_line = curr_line + '; ' + help_s

    if curr_line:
        send_whisper(nick, curr_line)
コード例 #16
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def showhelp(nick, _):
    access = db.player_get_access(nick)
    curr_line = ''

    for cmd, (lvl, _, hlp) in commands.iteritems():
        if access < lvl:
            continue

        if hlp[0] == '+':
            help_s = '!' + cmd + ' ' + hlp[1:]
        else:
            help_s = '!' + cmd + ' -- ' + hlp

        if len(curr_line + '; ' + help_s) > max_msg_len:
            send_whisper(nick, curr_line)
            curr_line = help_s
        else:
            curr_line = curr_line + '; ' + help_s

    if curr_line:
        send_whisper(nick, curr_line)
コード例 #17
0
def joinguild(nick, guild):
    if not guild:
        send_whisper(nick, "Usage: !joinguild Guild")
        return

    if db.player_join_guild(nick, guild, 20):
        send_whisper(nick, 'You joined guild "{}"'.format(guild))
    else:
        send_whisper(nick, 'Guild "{}" does not exist'.format(guild))
コード例 #18
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def joinguild(nick, guild):
    if not guild:
        send_whisper(nick, "Usage: !joinguild Guild")
        return

    if db.player_join_guild(nick, guild, 20):
        send_whisper(nick, 'You joined guild "{}"'.format(guild))
    else:
        send_whisper(nick, 'Guild "{}" does not exist'.format(guild))
コード例 #19
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def removeguild(nick, guild_name):
    if not guild_name:
        send_whisper(nick, "Usage: !removeguild Guild")
        return

    if db.guild_delete(guild_name):
        send_whisper(nick, 'Deleted guild "{}"'.format(guild_name))
    else:
        send_whisper(nick, 'Guild not found: "{}"'.format(guild_name))
コード例 #20
0
def removeguild(nick, guild_name):
    if not guild_name:
        send_whisper(nick, "Usage: !removeguild Guild")
        return

    if db.guild_delete(guild_name):
        send_whisper(nick, 'Deleted guild "{}"'.format(guild_name))
    else:
        send_whisper(nick, 'Guild not found: "{}"'.format(guild_name))
コード例 #21
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def addguild(nick, params):
    usage = 'Usage: !addguild Leader Guild (note: Leader can be quoted)'
    if not params:
        send_whisper(nick, usage)
        return

    leader, guild = parse_player_name(params)

    if len(leader) < 4 or len(guild) < 4:
        send_whisper(nick, usage)
        return

    if db.guild_create(guild):
        send_whisper(nick, 'Created guild "{}", leader is "{}"'.format(
            guild, leader))
    else:
        send_whisper(nick, "Error creating guild")
コード例 #22
0
def addguild(nick, params):
    usage = 'Usage: !addguild Leader Guild (note: Leader can be quoted)'
    if not params:
        send_whisper(nick, usage)
        return

    leader, guild = parse_player_name(params)

    if len(leader) < 4 or len(guild) < 4:
        send_whisper(nick, usage)
        return

    if db.guild_create(guild):
        send_whisper(
            nick, 'Created guild "{}", leader is "{}"'.format(guild, leader))
    else:
        send_whisper(nick, "Error creating guild")
コード例 #23
0
def remove(nick, player):
    if not player:
        send_whisper(nick, "Usage: !remove Player")
        return

    pinfo = db.player_info(player)
    if not pinfo:
        send_whisper(nick, '{} is not in any guild'.format(player))
        return

    gid, _, _ = db.player_info(nick)
    if gid != pinfo[0]:
        send_whisper(nick, '{} is not in your guild'.format(player))
        return

    broadcast(player, '{} was removed from your guild'.format(player), True)
    db.guild_remove_player(player)
    send_whisper(nick, 'You were removed from "{}" guild'.format(pinfo[1]))
コード例 #24
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def remove(nick, player):
    if not player:
        send_whisper(nick, "Usage: !remove Player")
        return

    pinfo = db.player_info(player)
    if not pinfo:
        send_whisper(nick, '{} is not in any guild'.format(player))
        return

    gid, _, _ = db.player_info(nick)
    if gid != pinfo[0]:
        send_whisper(nick, '{} is not in your guild'.format(player))
        return

    broadcast(player, '{} was removed from your guild'.format(player), True)
    db.guild_remove_player(player)
    send_whisper(nick, 'You were removed from "{}" guild'.format(pinfo[1]))
コード例 #25
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def invite(nick, player):
    if not player:
        send_whisper(nick, "Usage: !invite Player")
        return

    pinfo = db.player_info(player)
    if pinfo and pinfo[0]:
        send_whisper(nick, '"{}" is already a member of guild "{}"'.format(
            player, pinfo[1]))
        return

    online = online_users.online_users
    if player not in online:
        send_whisper(nick, '"{}" is not online'.format(player))
        return

    _, guild, _ = db.player_info(nick)
    invite_msg = ('You have been invited to the "{}" guild chat. '
                  'If you would like to accept this invitation '
                  'please reply "yes" and if not then "no"').format(guild)
    send_whisper(player, invite_msg)
    # FIXME: what if player is offline? online_list can be outdated
    pending_invitations[player] = guild
コード例 #26
0
def invite(nick, player):
    if not player:
        send_whisper(nick, "Usage: !invite Player")
        return

    pinfo = db.player_info(player)
    if pinfo and pinfo[0]:
        send_whisper(
            nick,
            '"{}" is already a member of guild "{}"'.format(player, pinfo[1]))
        return

    online = online_users.online_users
    if player not in online:
        send_whisper(nick, '"{}" is not online'.format(player))
        return

    _, guild, _ = db.player_info(nick)
    invite_msg = ('You have been invited to the "{}" guild chat. '
                  'If you would like to accept this invitation '
                  'please reply "yes" and if not then "no"').format(guild)
    send_whisper(player, invite_msg)
    # FIXME: what if player is offline? online_list can be outdated
    pending_invitations[player] = guild
コード例 #27
0
def hideinfo(nick, _):
    db.player_set_showinfo(nick, False)
    send_whisper(nick, "Information messages are hidden")
コード例 #28
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def status(nick, _):
    _, guild, access = db.player_info(nick)
    send_whisper(nick, 'Player:{}, Guild:{}, Access:{}'.format(
        nick, guild, access))
コード例 #29
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def hideinfo(nick, _):
    db.player_set_showinfo(nick, False)
    send_whisper(nick, "Information messages are hidden")
コード例 #30
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def showinfo(nick, _):
    db.player_set_showinfo(nick, True)
    send_whisper(nick, "Information messages are visible")
コード例 #31
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def leave(nick, _):
    info = db.player_info(nick)
    broadcast(nick, '"{}" left the guild'.format(nick), True)
    db.guild_remove_player(nick)
    send_whisper(nick, 'You left guild {}'.format(info[1]))
コード例 #32
0
def leave(nick, _):
    info = db.player_info(nick)
    broadcast(nick, '"{}" left the guild'.format(nick), True)
    db.guild_remove_player(nick)
    send_whisper(nick, 'You left guild {}'.format(info[1]))
コード例 #33
0
ファイル: chatbot.py プロジェクト: wushin/manachat
def answer_random(nick, message, is_whisper, answers):
    resp = random.choice(answers)
    if is_whisper:
        chat.send_whisper(nick, resp)
    else:
        mapserv.cmsg_chat_message(resp)
コード例 #34
0
ファイル: chatbot.py プロジェクト: mekolat/manachat
def answer_random(nick, message, is_whisper, answers):
    resp = random.choice(answers)
    if is_whisper:
        chat.send_whisper(nick, resp)
    else:
        mapserv.cmsg_chat_message(resp)
コード例 #35
0
def disband(nick, _):
    _, guild, _ = db.player_info(nick)
    if db.guild_delete(guild):
        send_whisper(nick, 'Deleted guild "{}"'.format(guild))
    else:
        send_whisper(nick, 'Error deleting guild "{}"'.format(guild))
コード例 #36
0
def status(nick, _):
    _, guild, access = db.player_info(nick)
    send_whisper(nick,
                 'Player:{}, Guild:{}, Access:{}'.format(nick, guild, access))
コード例 #37
0
ファイル: chatbot.py プロジェクト: mekolat/manachat
def answer_info(nick, message, is_whisper, match):
    if is_whisper:
        chat.send_whisper(nick, "answer to !info")
コード例 #38
0
def showinfo(nick, _):
    db.player_set_showinfo(nick, True)
    send_whisper(nick, "Information messages are visible")
コード例 #39
0
ファイル: handlers.py プロジェクト: mekolat/manachat
def disband(nick, _):
    _, guild, _ = db.player_info(nick)
    if db.guild_delete(guild):
        send_whisper(nick, 'Deleted guild "{}"'.format(guild))
    else:
        send_whisper(nick, 'Error deleting guild "{}"'.format(guild))
コード例 #40
0
ファイル: chatbot.py プロジェクト: wushin/manachat
def answer_info(nick, message, is_whisper, match):
    if is_whisper:
        chat.send_whisper(nick, "answer to !info")