def sendMaxUploadMessage(self, chatid, user): ''' This function governs the max upload reached message''' #Calculate the time difference dtime = datetime.timedelta(days=1) - (datetime.datetime.now() - user.firstuploadtime) minutes, seconds = divmod(dtime.seconds, 60) hours, minutes = divmod(minutes, 60) cost = int(40 + user.getReputation() / 1000) button_buyups = InlineKeyboardButton( text='buy 5 uploads for' + str(em.Pstr(cost)), callback_data='buy_uploads_' + str(cost)) keyboard = InlineKeyboardMarkup(inline_keyboard=[ [button_buyups], ]) rmk = keyboard self.bot.sendMessage( chatid, "Max upload reached! Missing {0}h and {1}m\nYou currently have {2}" .format(hours, minutes, user.getPointsStr(True)), reply_markup=rmk) print("max upload reached")
def makeKeyboardShow(self, deleteprice = 0): hidestr = 'Hide media '+ em.hidemedia_emoji cbstr = 'noshow_' + str(self.uid) button_hide = InlineKeyboardButton(text=hidestr, callback_data=cbstr) reportstr = 'report ' + em.report_emoji cbstr = 'report_' + str(self.uid) button_report = InlineKeyboardButton(text=reportstr, callback_data=cbstr) reportstr = 'report category ' + em.report_emoji cbstr = 'report_cat_' + str(self.catname) button_report_cat = InlineKeyboardButton(text=reportstr, callback_data=cbstr) if deleteprice != 0: price = em.Pstr(deleteprice) deletestr = 'delete {}'.format(price) cbstr = 'buy_delete_' + str(deleteprice) + "_" + str(self.uid) button_delete_pic = InlineKeyboardButton(text=deletestr, callback_data=cbstr) report_row = [button_hide, button_report] reportcat_row = [button_report_cat] if deleteprice != 0: deletepic_row = [button_delete_pic] keyboard = InlineKeyboardMarkup(inline_keyboard=[report_row, reportcat_row, deletepic_row]) else: keyboard = InlineKeyboardMarkup(inline_keyboard=[report_row, reportcat_row]) return keyboard
def addCategory(self, chatid, user): ''' This function is called when a user wants to create a category chatid must be private and is checked in the handle function user is te requesting user ''' # first send the available categories self.sendSelectCategoryMenu(chatid, sort=True) # create the message to purchase a category sdb = {} sdb["price"] = em.Pstr(self.categoryPrice(user), True) sdb["points"] = user.getPointsStr(True) m = "Send a category name\n" m += "<i>The name must be maximum 15 characters long and can contain only alphanumeric characters (a-z and A-Z and 1-10)</i>\n" m += "\n" m += "Create a category will cost {price} you have {points}\n" m += "/cancel\n" m = _(m, user.lang_tag) m = m.format(**sdb) self.bot.sendMessage(chatid, m, parse_mode="HTML") self.new_cat_req[chatid] = (True, False)
def help_msg_points(lang_tag): # variables sdb = {} sdb["pemoji"] = em.points_emoji sdb["1 point"] = str(em.Pstr(1)) sdb["5 points"] = str(em.Pstr(5)) sdb["remoji"] = em.reputation_emoji help_msg = "<b>- Points {pemoji} -</b>\n" help_msg += "You earn +{1 point} when you vote and +{5 points} when you /upload.\n" help_msg += "When somebody upvotes your content you earn +{1 point} but you lose -{1 point} if somebody downvotes.\n" help_msg += "Points are used to increase your reputation {remoji} (/buy_reputation), which increases the visibility of your media.\n" help_msg = _(help_msg, lang_tag) help_msg = help_msg.format(**sdb) return help_msg
def sendBuyReputation(self, chatid, bot, edit=False): # variable definition sdb = {} sdb['rep_points'] = self.getRepPointsStr() sdb['karma'] = self.getKarmaStr() sdb['rep'] = self.getReputationStr() sdb['points'] = self.getPointsStr() # message pattern definition msg = "<b>--- Buy reputation ---</b>\n" msg += "<i>Higher reputation ensures your media will be shown first, namely more reputation, more points</i>\n" msg += "\n" msg += "You currently have {rep_points}\n" msg += "You a karma of {karma}\n" msg += "This generates a reputation of {rep}\n" msg += "Reputation formula:\n <code>karma * reputation points</code>\n" msg += "\n" msg += "You have {points} points\n" msg += "Vould you like to buy more RP?\n" # message translation msg = _(msg, self.lang_tag) msg = msg.format(**sdb) blist = [] qrp = 1 for i in range(3): total_cost = calc_rep_cost(self, qrp) #variable def sdb = {} sdb["qrp"] = str(em.RPstr(qrp)) sdb["points"] = str(em.Pstr(total_cost)) buyrptext = _("Buy {qrp} for {points}", self.lang_tag) buyrptext = buyrptext.format(**sdb) button = [InlineKeyboardButton(text= buyrptext, callback_data = "buy_rp_" + str(qrp))] blist.append(button) qrp = (i+1)*2 # button = [InlineKeyboardButton(text=_("Calculate media probability (not working)", self.lang_tag), # callback_data = "buy_calcp"),] # blist.append(button) rmk = InlineKeyboardMarkup(inline_keyboard = blist) if edit: assert type(chatid) == tuple and len(chatid) == 2 bot.editMessageText(chatid, msg, parse_mode="HTML", reply_markup = rmk) else: bot.sendMessage(chatid, msg, parse_mode="HTML", reply_markup = rmk)
def makeKeyboardVote(self, deleteprice = 0): upvstr = 'like '+ em.upvote_emoji +' - ' + str(self.upvote) cbstr = 'v_like_' + str(self.uid) button_upvote = InlineKeyboardButton(text=upvstr, callback_data=cbstr) downvstr = 'dislike ' + em.downvote_emoji + ' - ' + str(self.downvote) cbstr = 'v_dislike_' + str(self.uid) button_downvote = InlineKeyboardButton(text=downvstr, callback_data=cbstr) hidestr = 'Hide media ' + em.hidemedia_emoji cbstr = 'noshow_' + str(self.uid) button_hide = InlineKeyboardButton(text=hidestr, callback_data=cbstr) reportstr = 'report ' + em.report_emoji cbstr = 'report_' + str(self.uid) button_report = InlineKeyboardButton(text=reportstr, callback_data=cbstr) reportstr = 'report category ' + em.report_emoji cbstr = 'report_cat_' + str(self.catname) button_report_cat = InlineKeyboardButton(text=reportstr, callback_data=cbstr) if deleteprice != 0: price = em.Pstr(deleteprice) deletestr = 'delete {}'.format(price) cbstr = 'buy_delete_' + str(deleteprice) + "_" + str(self.uid) button_delete_pic = InlineKeyboardButton(text=deletestr, callback_data=cbstr) ld_row = [button_upvote, button_downvote] report_row = [button_hide, button_report] reportcat_row = [button_report_cat] if deleteprice != 0: deletepic_row = [button_delete_pic] keyboard = InlineKeyboardMarkup(inline_keyboard=[ld_row, report_row, reportcat_row, deletepic_row]) else: keyboard = InlineKeyboardMarkup(inline_keyboard=[ld_row, report_row, reportcat_row]) return keyboard
def getPointsStr(self, long = False): return str(em.Pstr(self.points, long))
def getUploadCategory(self, msg): ''' This function is the core function of the uploading process the function checks if the media can be created, the function is activated only if the user requested an upload (either by direct posting or command /upload) and the user provided a category name categoryname: must be the lowercase representation of one of the category if the user chosed a valid category the program will try to create a media ''' chatid = msg.chat.id if self.getuploadCategory[chatid] == True and self.getuploadMedia[ chatid] == "success": # get the category message categories duser = self.user_profile_db.getData(msg.mfrom.id) user = duser.getData() if msg.content.type == "text": usercatname = msg.content.text.lower() # check if category is a real category catnamelist = self.getCategoriesNamesList() if usercatname in catnamelist: # get the user user.tmp_content["cateogry"] = usercatname.lower() # preventively # change this might create error print("try to create media") # temporarily assign none to the short id mediavote = ContentVote(None, user.id, user.tmp_content["media"], user.tmp_content["cateogry"]) # if the picture is already present isoc = True for media in self.media_vote_db.values(): if media.getData( ).content.file_id == mediavote.content.file_id: isoc = False if isoc: dmediavote = Data(mediavote.id, mediavote) if self.media_vote_db.isNew(dmediavote): # assign here the uid self.uid += 1 dmediavote.getData().uid = self.uid # add the data to the database self.media_vote_db.addData(dmediavote) self.media_vote_db.updateDb() # mange the users data user.dayuploads += 1 user.points += 5 # update the user data duser.setData(user) self.user_profile_db.updateDb() # reset the upload media switches self.getuploadCategory[chatid] = False self.getuploadMedia[chatid] = False self.getupload[chatid] = False self.bot.sendMessage( chatid, _("Content uploaded successfully", user.lang_tag)) self.bot.sendMessage( chatid, "You earned " + str(em.Pstr(5)) + " /profile") print(dmediavote.getData(), "added successfully") return True else: self.bot.sendMessage( chatid, _("Media already in database", user.lang_tag)) else: self.bot.sendMessage( chatid, _( "Category not found\nYou can add the category using /add_category", user.lang_tag)) else: self.bot.sendMessage(chatid, _("Message must be text", user.lang_tag)) self.bot.sendMessage( chatid, "Category: Something went wrong use /upload again") self.getuploadCategory[chatid] = False self.getuploadMedia[chatid] = False self.getupload[chatid] = False
def getCategoryName(self, chatid, user, content): ''' this function gets the name from the chat once the user wants to add a category ''' # check if the user requested a "add category" if self.new_cat_req[chatid][0]: if (content is not None and content.type == "text" and not content.text.startswith("/")): # check validity of category name # a category must be max 15 character long categoryname = content.text is_valid_name = True if len(categoryname) > 15: is_valid_name = False validcharset = string.ascii_lowercase + string.ascii_uppercase + string.digits for c in categoryname: if c not in validcharset: is_valid_name = False break if (is_valid_name and categoryname.lower() in map( lambda s: s.lower(), list(self.categories_db.keys())) and categoryname.lower() != "top"): is_valid_name = False # if the name is valid # create a message where the buttons displays the possible tags if is_valid_name: # create message price = self.categoryPrice(user) sdb = {} sdb["catname"] = categoryname sdb["price"] = em.Pstr(price, long=True) m = "Select a tag for the category\n" m += "<i>Your category will be banned if you have for example p**n in a safe for work (SFW-tag category</i>\nThis action will cost you {price}\n\n" m += "category: {catname}\n\n/main_menu" m = _(m, user.lang_tag) m = m.format(**sdb) # create keyboard strtag = "nsfw" cbstr = 'createcat_' + categoryname + "_" + strtag + "_" + str( price) button_nsfw = InlineKeyboardButton(text=strtag, callback_data=cbstr) strtag = "sfw" cbstr = 'createcat_' + categoryname + "_" + strtag + "_" + str( price) button_sfw = InlineKeyboardButton(text=strtag, callback_data=cbstr) strtag = "gore" cbstr = 'createcat_' + categoryname + "_" + strtag + "_" + str( price) button_gore = InlineKeyboardButton(text=strtag, callback_data=cbstr) ld_row = [button_nsfw, button_sfw, button_gore] keyboard = InlineKeyboardMarkup(inline_keyboard=[ld_row]) self.bot.sendMessage(chatid, m, parse_mode="HTML", reply_markup=keyboard) self.new_cat_req[chatid] = (True, True) else: self.bot.sendMessage( chatid, _( "Name not valid (either character or category already present) /add_category again or /main_menu", user.lang_tag)) self.new_cat_req[chatid] = (False, False) else: self.bot.sendMessage( chatid, _( "Operation aborted (must be text and not a command) /add_category again or /main_menu", user.lang_tag)) self.new_cat_req[chatid] = (False, False)