def group_administration(update, context): # this changes the admin mode setting group = context.user_data["group"] # checks current setting of administration, we need to flip that around if group.administration: # disabling an active administration mode is easy group.administration = False else: # activating it is not. we need to make sure the bot is an admin with the appropriate rights bot_admin = context.bot.get_chat_member(chat_id=group.id, user_id=context.bot.id) query = update.callback_query # if the bot is not an admin, the other attributes won't be there, that is why we have two checks if bot_admin.status != "administrator": query.answer(strings.NOT_ADMIN, show_alert=True) return # bot is admin, but does it have the correct rights? if not bot_admin.can_delete_messages or not bot_admin.can_restrict_members: query.answer(strings.NOT_ADMIN, show_alert=True) return # the both returns previously made sure we can only be here with the correct admin rights so we good group.administration = True # here we add the information to the db new_group = database.insert_group_administration(group.id, group.administration) # updating our cache context.user_data["group"] = new_group # returning it to the edit function for the message edit(update, new_group)
def group_reply(update, context): group = context.user_data["group"] if group.reply: group.reply = False to_pass = [x for x in group.admins if x not in group.off] else: group.reply = True to_pass = False new_group = database.insert_group_reply(group.id, to_pass) context.user_data["group"] = new_group edit(update, new_group)
def group_report(update, context): group = context.user_data["group"] # wanted direction: both => @admin => /report => both if group.admin: if group.report: new = "a" else: new = "r" else: new = "b" new_group = database.insert_group_report(group.id, new) context.user_data["group"] = new_group edit(update, new_group)
def parsePostFile(self, filename, hdrtext): try: f = open(filename, 'r') lines = f.readlines() except IOError: try: f = open(filename, 'w') except IOError, err: print err sys.exit() utils.edit(hdrtext, f) raise FileProcessorRetry()
def redeemDays(info): points = info[5] utils.clear() print("You currently have " + points + " points to spend.") if int(points) >= 25000: daysAvailable = floor(int(points)/25000) print("You may redeem " + str(daysAvailable) + " free days.") print("How many would you like to redeem?") toRedeem = int(input("> ")) if toRedeem <= daysAvailable: utils.edit(info[3], 5, toRedeem*25000, 0) utils.edit(info[3], 4, toRedeem, 1) print("Days redeemed.") else: print("You do not have enough points to redeem any free days.")
def run(self, header, opts): proxy = _getProxy(header) comment = proxy.getComment(self.commentid) commenttext = "COMMENTID: %s\n" % (self.commentid) commenttext += "PARENTID: %s\n" % (comment['parent']) commenttext += "COMMENTSTATUS: %s\n" % (comment['status']) commenttext += "AUTHOR: %s\n" % (comment['author']) if comment['author_url']: commenttext += "AUTHORURL: %s\n" % (comment['author_url']) commenttext += "AUTHOREMAIL: %s\n" % (comment['author_email']) commenttext += "\n%s" % (html2md.convert(comment['content'])) fd = utils.edit(commenttext) if fd == None: print "Nothing to do with comment." fp = FileProcessor(**{'addpostcats' : False, 'publish' : True, 'posttime' : None, 'allblogs' : False, 'comment' : True, 'charset': opts.charset, }) try: header_text, commenttext = fp.parsePostFile(fd.name, '') except FileProcessorError, err_msg: print err_msg sys.exit()
def story(title=""): if request.method=="GET": if 'un' not in session or session['un']==0: return redirect(url_for("home")) else: user = session['un'] story = utils.getPost(title) if len(story) == 0: return redirect(url_for("blog")) #return render_template("home.html") else: story = story[0] return render_template("story.html",un=user,title=story[1],user=story[0],content=story[2]) else: content = request.form['post_content'] utils.edit(session['un'], title, content) return redirect(url_for("profile"))
def _display(view): with utils.edit(view) as ed: size = view.size() view.set_read_only(False) view.insert(ed, size, str(self)) view.set_read_only(True) # TODO: this scrolling is lame and centers text :/ view.show(size)
def story(title=""): if request.method == "GET": if 'un' not in session or session['un'] == 0: return redirect(url_for("home")) else: user = session['un'] story = utils.getPost(title) if len(story) == 0: return redirect(url_for("blog")) #return render_template("home.html") else: story = story[0] return render_template("story.html", un=user, title=story[1], user=story[0], content=story[2]) else: content = request.form['post_content'] utils.edit(session['un'], title, content) return redirect(url_for("profile"))
def group_mention(update, context): group = context.user_data["group"] user_id = update.effective_user.id # mention => PM => off => mention if group.reply: if user_id in group.pm: new = "o" elif user_id in group.off: new = "m" else: new = "p" # PM => off => PM else: if user_id in group.pm: new = "o" else: new = "p" new_group = database.insert_group_mention(group.id, group.reply, new, user_id) context.user_data["group"] = new_group edit(update, new_group)
Make sure that this loop always executes, regardless of whether there are actually options. The config file is processed through this loop and the program will break if that code does not run ''' header = Header() runeditor = options.check(header) emptyheader_text = header.buildPostHeader(options) ''' Unfortunately, determining when to run the editor for creating a blogpost is a bit tricky. If `blogtool` is invoked by itself do so. If no files are supplied and certain options are specified that logically mean we want to create a post (see options.py for which ones return `runeditor`) BUT we haven't editted a comment, then do so. Finally, if only 3 arguments are supplied on the command line and the blogname is set, meaning the following command was run: > blogtool.py -b 'blogname' then run the editor. ''' if len(sys.argv) == 1 or \ (len(filelist) == 0 and runeditor and not options.opts.commentid) or \ (len(sys.argv) == 3 and options.opts.blogname is not None): fd = utils.edit(emptyheader_text) if fd == None: print "Nothing to do, exiting." sys.exit() filelist.append(fd.name)