Example #1
0
 def mp_invite():
     userID = userUtils.getID(fro)
     if not can_user_touch_lobby(get_match_id_from_channel(chan), userID,
                                 True):
         return False
     if len(message) < 2:
         raise exceptions.invalidArgumentsException(
             "Wrong syntax: !mp invite <username>")
     username = message[1].strip()
     if not username:
         raise exceptions.invalidArgumentsException(
             "Please provide a username")
     userID = userUtils.getIDSafe(username)
     if userID is None:
         raise exceptions.userNotFoundException("No such user")
     token = glob.tokens.getTokenFromUserID(userID, ignoreIRC=True)
     if token is None:
         raise exceptions.invalidUserException(
             "That user is not connected to bancho right now.")
     _match = glob.matches.matches[get_match_id_from_channel(chan)]
     _match.invite(999, userID)
     token.enqueue(
         serverPackets.notification(
             "Please accept the invite you've just received from {} to "
             "enter your tourney match.".format(glob.BOT_NAME)))
     return "An invite to this match has been sent to {}".format(username)
Example #2
0
def report(fro, chan, message):
    msg = ""
    try:
        # TODO: Rate limit
        # Get username, report reason and report info
        target, reason, additionalInfo = message[0], message[1], message[2]
        target = chat.fixUsernameForBancho(target)

        # Make sure the target is not foka
        if target == glob.BOT_NAME:
            raise exceptions.invalidUserException()

        # Make sure the user exists
        targetID = userUtils.getID(target)
        if targetID == 0:
            raise exceptions.userNotFoundException()

        # Make sure that the user has specified additional info if report reason is 'Other'
        if reason.lower() == "other" and not additionalInfo:
            raise exceptions.missingReportInfoException()

        # Get the token if possible
        chatlog = ""
        token = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
        if token is not None:
            chatlog = token.getMessagesBufferString()

        # Everything is fine, submit report
        glob.db.execute(
            "INSERT INTO reports (id, from_uid, to_uid, reason, chatlog, time, assigned) VALUES (NULL, %s, %s, %s, %s, %s, 0)",
            [userUtils.getID(fro), targetID, "{reason} - ingame {info}".format(reason=reason, info="({})".format(
                additionalInfo) if additionalInfo is not None else ""), chatlog, int(time.time())])
        msg = "You've reported {target} for {reason}{info}. A Community Manager will check your report as soon as possible. Every !report message you may see in chat wasn't sent to anyone, so nobody in chat, but admins, know about your report. Thank you for reporting!".format(
            target=target, reason=reason, info="" if additionalInfo is None else " (" + additionalInfo + ")")
        adminMsg = "{user} has reported {target} for {reason} ({info})".format(user=fro, target=target, reason=reason,
                                                                               info=additionalInfo)

        # Log report in #admin and on discord
        chat.sendMessage(glob.BOT_NAME, "#admin", adminMsg)
        log.warning(adminMsg, discord="cm")
    except exceptions.invalidUserException:
        msg = "Hello, {} here! You can't report me. I won't forget what you've tried to do. Watch out.".format(
            glob.BOT_NAME)
    except exceptions.invalidArgumentsException:
        msg = "Invalid report command syntax. To report an user, click on it and select 'Report user'."
    except exceptions.userNotFoundException:
        msg = "The user you've tried to report doesn't exist."
    except exceptions.missingReportInfoException:
        msg = "Please specify the reason of your report."
    except:
        raise
    finally:
        if msg != "":
            token = glob.tokens.getTokenFromUsername(fro)
            if token is not None:
                if token.irc:
                    chat.sendMessage(glob.BOT_NAME, fro, msg)
                else:
                    token.enqueue(serverPackets.notification(msg))
    return False
Example #3
0
 def mpInvite():
     if len(message) < 2:
         raise exceptions.invalidArgumentsException(
             "Wrong syntax: !mp invite <username>")
     username = message[1]
     userID = userUtils.getIDSafe(username)
     if userID is None:
         raise exceptions.userNotFoundException("No such user")
     token = glob.tokens.getTokenFromUserID(userID, ignoreIRC=True)
     if token is None:
         raise exceptions.invalidUserException(
             "That user is not connected to bancho right now.")
     _match = glob.matches.matches[getMatchIDFromChannel(chan)]
     _match.invite(999, userID)
     token.enqueue(
         serverPackets.notification(
             "Please accept the invite you've just received from FokaBot to "
             "enter your tourney match."))
     return "An invite to this match has been sent to {}".format(username)
Example #4
0
 def invite(response, token, sender, channel, message):
     if len(message) < 1:
         raise exceptions.invalidArgumentsException(
             "Wrong syntax: !mp invite <username>")
     username = message[0].strip()
     if not username:
         raise exceptions.invalidArgumentsException(
             "Please provide a username")
     userID = lookupUser(username)
     token = glob.tokens.getTokenFromUserID(userID, ignoreIRC=True)
     if token is None:
         raise exceptions.invalidUserException(
             "That user is not connected to bancho right now.")
     _match = getCurrentMatch(channel)
     _match.invite(1, userID, force=True)
     token.enqueue(
         serverPackets.notification(
             "Please accept the invite you've just received from {} to "
             "enter your tourney match.".format(glob.BOT_NAME)))
     response.setContent(token, "Invited {} to the game.".format(username))
     response.listen_in = [token.token]