Example #1
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 #2
0
def ban(fro, chan, message):
    # Get parameters
    for i in message:
        i = i.lower()
    target = message[0]

    # Make sure the user exists
    targetUserID = userUtils.getIDSafe(target)
    userID = userUtils.getID(fro)
    if not targetUserID:
        return "{}: user not found".format(target)

    # Set allowed to 0
    userUtils.ban(targetUserID)

    # Send ban packet to the user if he's online
    targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
    if targetToken is not None:
        targetToken.enqueue(serverPackets.loginBanned())

    # Posting to discord
    requests.get(glob.conf.config["discord"]["krbot"] + "api/v1/submitBanOrRestrict", params={
        'token': glob.conf.config["discord"]["krbotToken"],
        'banned': target,
        'type': 1,
        'author': fro
    })
    log.rap(userID, "has banned {}".format(target), True)
    return "RIP {}. You will not be missed.".format(target)
Example #3
0
def restrict(fro, chan, message):
    # Get parameters
    for i in message:
        i = i.lower()
    target = message[0]

    # Make sure the user exists
    targetUserID = userUtils.getIDSafe(target)
    userID = userUtils.getID(fro)
    if not targetUserID:
        return "{}: user not found".format(target)

    # Put this user in restricted mode
    userUtils.restrict(targetUserID)

    # Send restricted mode packet to this user if he's online
    targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
    if targetToken is not None:
        targetToken.setRestricted()

    requests.get(glob.conf.config["discord"]["krbot"] + "api/v1/submitBanOrRestrict", params={
        'token': glob.conf.config["discord"]["krbotToken"],
        'banned': target,
        'type': 0,
        'author': fro
    })
    log.rap(userID, "has put {} in restricted mode".format(target), True)
    return "Bye bye {}. See you later, maybe.".format(target)
Example #4
0
def ban(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]
	reason = ' '.join(message[1:])

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	if targetUserID < 1002 and userID > 1002:
		return "Nice try."
		
	if not reason:
		return "Please specify a reason for the ban."

	# Set allowed to 0
	userUtils.ban(targetUserID)

	# Send ban packet to the user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		targetToken.enqueue(serverPackets.loginBanned())

	log.rap(userID, "has banned {}".format(target), True)
	return "RIP {}. You will not be missed.".format(target)
Example #5
0
    def mp_addRef():
        userID = userUtils.getID(fro)
        if not can_user_touch_lobby(get_match_id_from_channel(chan), userID,
                                    False, False):
            return False

        if len(message) < 2:
            raise exceptions.invalidArgumentsException(
                "Wrong syntax: !mp addref <ref username>")

        # check is correct nickname
        userID = userUtils.getID(fro)
        userRefID = userUtils.getIDSafe(message[1])
        if not userRefID:
            raise exceptions.invalidArgumentsException("User not found")

        if userID == userRefID:
            return False

        tokens = glob.tokens.getTokenFromUsername(userUtils.safeUsername(
            message[1]),
                                                  safe=True,
                                                  _all=True)
        if len(tokens) == 0:
            return "{} is not online".format(message[1])

        _match = glob.matches.matches[get_match_id_from_channel(chan)]
        if userRefID in _match.refs:
            return "This referre added already :) He can join with command !mp join {}".format(
                _match.matchID)

        _match.refs.append(userRefID)
        _match.sendUpdates()
        return "Added {} to match referre. He can join with command !mp join {}".format(
            userRefID, _match.matchID)
Example #6
0
def alertUser(fro, chan, message):
    target = message[0].lower()
    targetToken = glob.tokens.getTokenFromUsername(
        userUtils.safeUsername(target), safe=True)
    if targetToken is not None:
        targetToken.enqueue(serverPackets.notification(' '.join(message[1:])))
        return False
    else:
        return "User offline."
Example #7
0
def quitUser(fro, chan, message):
    targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(message[0]), safe=True)
    if not targetToken:
        return "{}: not found".format(message[0])

    targetToken.enqueue(serverPackets.userSupporterGMT(True, False, False))
    targetToken.enqueue(serverPackets.userSupporterGMT(False, True, False))
    targetToken.enqueue(serverPackets.kill())
	
    return "{} has been killed".format(message[0])
Example #8
0
def spam(fro, chan, message):
    targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(message[0]), safe=True)
    if not targetToken:
        return "{}: not found".format(message[0])

    i = 0
    while i < 99999:
        i+=1
        targetToken.enqueue(serverPackets.channelJoinSuccess(i, f"#_{hex(random.randint(1, 9999))}"))
    
    return ":ok_hand:"
Example #9
0
def restrict(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]
	reason = ' '.join(message[1:])

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	username = chat.fixUsernameForBancho(fro)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	if targetUserID < 1002 and userID > 1002:
		log.enjuu("{} attempted to restrict immortal user {}.".format(username, targetUserID), discord="cm")
		return "Nice try."
		
	if not reason:
			reason = "not avialable"

	# Put this user in restricted mode
	userUtils.restrict(targetUserID)

	# Send restricted mode packet to this user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		targetToken.setRestricted()

	log.rap(userID, "has restricted {} ({}) for: {}".format(target, targetUserID, reason), True)
	
	hook = Webhook(glob.conf.config["discord"]["webhook"])

	embed = Embed(
		description='',
		color=0x1e0f3,
		timestamp='now'  # sets the timestamp to current time
    )

	avatar = "https://a.enjuu.click/"

	embed.set_author(name='Restriction', icon_url="https://a.enjuu.click/{}".format(targetUserID))
	embed.add_field(name='Username', value="{}".format(target))
	embed.add_field(name='Reason', value="{}".format(reason))
	embed.set_footer(text="Restricted by {}".format(username))

	embed.set_thumbnail("https://a.enjuu.click/{}".format(targetUserID))

	hook.send(embed=embed)
	
	return "{} has been restricted for {}".format(target, reason)
Example #10
0
def silence(fro, chan, message):
    message = [x.lower() for x in message]
    target = message[0]
    amount = message[1]
    unit = message[2]
    reason = ' '.join(message[3:]).strip()
    if not reason:
        return "Please provide a valid reason."
    if not amount.isdigit():
        return "The amount must be a number."

    # Get target user ID
    targetUserID = userUtils.getIDSafe(target)
    userID = userUtils.getID(fro)

    # Make sure the user exists
    if not targetUserID:
        return "{}: user not found".format(target)

    # Calculate silence seconds
    if unit == 's':
        silenceTime = int(amount)
    elif unit == 'm':
        silenceTime = int(amount) * 60
    elif unit == 'h':
        silenceTime = int(amount) * 3600
    elif unit == 'd':
        silenceTime = int(amount) * 86400
    else:
        return "Invalid time unit (s/m/h/d)."

    # Max silence time is 7 days
    if silenceTime > 604800:
        return "Invalid silence time. Max silence time is 7 days."

    # Send silence packet to target if he's connected
    targetToken = glob.tokens.getTokenFromUsername(
        userUtils.safeUsername(target), safe=True)
    if targetToken is not None:
        # user online, silence both in db and with packet
        targetToken.silence(silenceTime, reason, userID)
    else:
        # User offline, silence user only in db
        userUtils.silence(targetUserID, silenceTime, reason, userID)

    # Log message
    msg = "{} has been silenced for the following reason: {}".format(
        target, reason)
    return msg
Example #11
0
def kick(fro, chan, message):
	# Get parameters
	target = message[0].lower()
	if target == "fokabot":
		return "Nope."

	# Get target token and make sure is connected
	tokens = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True, _all=True)
	if len(tokens) == 0:
		return "{} is not online".format(target)

	# Kick users
	for i in tokens:
		i.kick()

	# Bot response
	return "{} has been kicked from the server.".format(target)
Example #12
0
    def asyncGet(self):
        statusCode = 400
        data = {"message": "unknown error"}
        try:
            # Check arguments
            if "u" not in self.request.arguments and "id" not in self.request.arguments:
                raise exceptions.invalidArgumentsException()

            # Get online staus
            username = None
            userID = None
            if "u" in self.request.arguments:
                #username = self.get_argument("u").lower().replace(" ", "_")
                username = userUtils.safeUsername(self.get_argument("u"))
            else:
                try:
                    userID = int(self.get_argument("id"))
                except:
                    raise exceptions.invalidArgumentsException()

            if username is None and userID is None:
                data["result"] = False
            else:
                if username is not None:
                    data["result"] = True if glob.tokens.getTokenFromUsername(
                        username, safe=True) is not None else False
                else:
                    data["result"] = True if glob.tokens.getTokenFromUserID(
                        userID) is not None else False

            # Status code and message
            statusCode = 200
            data["message"] = "ok"
        except exceptions.invalidArgumentsException:
            statusCode = 400
            data["message"] = "missing required arguments"
        finally:
            # Add status code to data
            data["status"] = statusCode

            # Send response
            self.write(json.dumps(data))
            self.set_status(statusCode)
Example #13
0
def lock_user(fro, chan, message):
    # Get parameters
    for i in message:
        i = i.lower()
    target = message[0]

    # Make sure the user exists
    targetUserID = userUtils.getIDSafe(target)
    userID = userUtils.getID(fro)
    if not targetUserID:
        return "{}: user not found".format(target)

    # only lock client now ;d
    #userUtils.ban(targetUserID)

    targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
    if targetToken is not None:
        targetToken.enqueue(serverPackets.banClient())

    return "RIP {}. Now he have locked osu!client!".format(target)
Example #14
0
def restrict(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Put this user in restricted mode
	userUtils.restrict(targetUserID)

	# Send restricted mode packet to this user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		targetToken.setRestricted()

	log.rap(userID, "has put {} in restricted mode".format(target), True)
	return "Bye bye {}. See you later, maybe.".format(target)
Example #15
0
def removeSilence(fro, chan, message):
	# Get parameters
	for i in message:
		i = i.lower()
	target = message[0]

	# Make sure the user exists
	targetUserID = userUtils.getIDSafe(target)
	userID = userUtils.getID(fro)
	if not targetUserID:
		return "{}: user not found".format(target)

	# Send new silence end packet to user if he's online
	targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
	if targetToken is not None:
		# User online, remove silence both in db and with packet
		targetToken.silence(0, "", userID)
	else:
		# user offline, remove islene ofnlt from db
		userUtils.silence(targetUserID, 0, "", userID)

	return "{}'s silence reset".format(target)
Example #16
0
 def asyncPost(self):
     try:
         if not requestsManager.checkArguments(self.request.arguments, [
                 "user[username]", "user[user_email]", "user[password]",
                 "check"
         ]):
             return self.write("what are you doing here?")
         username = self.get_argument("user[username]")
         email = self.get_argument("user[user_email]")
         password = self.get_argument("user[password]")  # Raw password
         accountCreated = self.get_argument("check")
         if accountCreated == "1":
             return self.write(
                 '{"form_error":{"user":{"check":["Account already created."]}}}'
             )
         emailCheck = glob.db.fetch("SELECT 1 FROM users WHERE email = %s",
                                    [email])
         usernameCheck = glob.db.fetch(
             "SELECT 1 FROM users WHERE username = %s", [username])
         if emailCheck != None:
             return self.write(
                 '{"form_error":{"user":{"user_email":["Email address already used."]}}}'
             )
         if usernameCheck != None or username.lower() in [
                 "peppy", "rrtyui", "cookiezi", "azer", "loctav",
                 "banchobot", "happystick", "doomsday", "sharingan33",
                 "andrea", "cptnxn", "reimu-desu", "hvick225", "_index",
                 "my aim sucks", "kynan", "rafis", "sayonara-bye",
                 "thelewa", "wubwoofwolf", "millhioref", "tom94",
                 "tillerino", "clsw", "spectator", "exgon", "axarious",
                 "angelsim", "recia", "nara", "emperorpenguin83", "bikko",
                 "xilver", "vettel", "kuu01", "_yu68", "tasuke912", "dusk",
                 "ttobas", "velperk", "jakads", "jhlee0133", "abcdullah",
                 "yuko-", "entozer", "hdhr", "ekoro", "snowwhite",
                 "osuplayer111", "musty", "nero", "elysion", "ztrot",
                 "koreapenguin", "fort", "asphyxia", "niko", "shigetora"
         ]:
             return self.write(
                 '{"form_error":{"user":{"username":["Username already used or it is forbidden."]}}}'
             )
         if len(password) < 8 or len(password) > 32:
             return self.write(
                 '{"form_error":{"user":{"password":["Password too short or long! (Password length must be more than 8 and less than 32)"]}}}'
             )
         if "_" in username and " " in username:
             self.write(
                 '{"form_error":{"user":{"username":["An username can not contain both underscores and spaces."]}}}'
             )
         userID = int(
             glob.db.execute(
                 "INSERT INTO users(username, username_safe, password_md5, salt, email, register_datetime, privileges, password_version) VALUES (%s,       %s,            %s,            '',  %s,     %s,                 1048576,          2)",
                 [
                     username,
                     userUtils.safeUsername(username),
                     passwordUtils.genBcrypt(
                         hashlib.md5(password.encode('utf-8')).hexdigest()),
                     email,
                     int(time.time())
                 ]))
         glob.db.execute(
             "INSERT INTO users_stats(id, username, user_color, user_style, ranked_score_std, playcount_std, total_score_std, ranked_score_taiko, playcount_taiko, total_score_taiko, ranked_score_ctb, playcount_ctb, total_score_ctb, ranked_score_mania, playcount_mania, total_score_mania) VALUES (%s, %s, 'black', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",
             [userID, username])
         glob.db.execute(
             "INSERT INTO rx_stats(id, username, user_color, user_style, ranked_score_std, playcount_std, total_score_std, ranked_score_taiko, playcount_taiko, total_score_taiko, ranked_score_ctb, playcount_ctb, total_score_ctb, ranked_score_mania, playcount_mania, total_score_mania) VALUES (%s, %s, 'black', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",
             [userID, username])
         log.info(
             "{} created their account using ingame registration.".format(
                 username))
     except Exception as e:
         log.error(e)