def handleRemoveFriendRequestCont(chat, req): handles = [util.cleanString(s) for s in req.split(',')] userInfos = cf.getUserInfos(handles) if userInfos == False or len(userInfos) == 0 or "handle" not in userInfos[0]: chat.sendMessage("π» No user with this handle!") else: for user in userInfos: if "handle" in user: db.deleteFriendOfUser(user['handle'], chat.chatId) chat.sendMessage("π User `" + user['handle'] + "` was removed from your friends. If this is one of your Codeforces friends, they will be added automatically again in case you added your API-key. If so, just disable notifications for this user in the settings.") setOpenCommandFunc(chat.chatId, None)
def handleAddKey(chat, key): if util.cleanString(key) == "no": bot.sendSetupFinished(chat) return if not key.isalnum(): chat.sendMessage( "Your API-key is incorrect, it may only contain alphanumerical letters. Please try again:" ) return chat.apikey = key bot.setOpenCommandFunc(chat.chatId, handleAddSecret) chat.sendMessage("Enter your secret:")
def handleSetUserHandle(chat: ChatClass, handle): handle = util.cleanString(handle) if util.cleanString(handle) == 'no': bot.sendSetupFinished(chat) return userInfos = cf.getUserInfos([handle]) if userInfos == False or len( userInfos) == 0 or "handle" not in userInfos[0]: chat.sendMessage("Γ°ΕΈβΒ» No user with this handle! Try again:") else: bot.setOpenCommandFunc(chat.chatId, None) chat.handle = userInfos[0]['handle'] db.addFriends(chat.chatId, [userInfos[0]['handle']], chat.notifyLevel) rating = userInfos[0].get('rating', 0) chat.sendNotification("Welcome `" + userInfos[0]['handle'] + "`. Your current rating is " + str(rating) + " " + util.getUserSmiley(rating) + ".") if chat.apikey is None: chat.sendNotification( "Do you want import your friends from Codeforces? Then, I need your Codeforces API key." ) handleSetAuthorization(chat, "")
def handleMessage(chat, text): logger.info("-> " + text + " <- (" + ((chat.handle + ": ") if chat.handle else "") + str(chat.chatId) + ")") text = text.replace("@codeforces_live_bot", "") text = text.replace("@codeforces_live_testbot", "") msgSwitch = { "/start": handleStart, "/rating": handleRatingRequest, "/friend_ratings": handleFriendRatingsRequest, "/add_friend": handleAddFriendRequest, "/remove_friend": handleRemoveFriendRequest, "/settings": settings.handleSettings, "/current_standings": standings.sendStandings, "/upcoming": upcoming.handleUpcoming, "/help": handleHelp } func = msgSwitch.get(util.cleanString(text), noCommand) func(chat, text)
def handleAddFriendRequestCont(chat, req): handles = [util.cleanString(s) for s in req.split(',')] resMsg = [] didnotwork = [] for handle in handles: userInfo = cf.getUserInfos([handle]) if userInfo == False or len(userInfo) == 0 or "handle" not in userInfo[0]: didnotwork.append("`" + handle + "`") else: user = userInfo[0] db.addFriends(chat.chatId, [user['handle']], chat.notifyLevel) rating = user.get('rating', 0) resMsg.append(util.getUserSmiley(rating) + " User `" + user['handle'] + "` with rating " + str(rating) + " added.") if len(didnotwork) > 0: resMsg.append("π» No user" + ("" if len(didnotwork) == 1 else "s") + " with handle " + ", ".join(didnotwork) + "! Please try again for those:") else: setOpenCommandFunc(chat.chatId, None) chat.sendMessage("\n".join(resMsg))
def handleRatingRequestCont(chat, handleStr): handleStr = util.cleanString(handleStr) handles = handleStr.split(',') handles = [util.cleanString(h) for h in handles] chat.sendMessage(ratingsOfUsers(handles)) setOpenCommandFunc(chat.chatId, None)