def reload_contacts_cb(data, buffer, args): global contacts csv_file = weechat.info_get('weechat_dir', '') + '/python/weesms.csv' try: contacts_csv = csv.reader(open(csv_file, 'r')) weechat.nicklist_remove_group(smsbuffer, contacts) contacts = weechat.nicklist_add_group(smsbuffer, '', 'contacts', '', 1) for c in contacts_csv: weechat.nicklist_add_nick(smsbuffer, contacts, c[0], '', '@', '', 1) contacts_dict[c[0]] = c[1] weechat.prnt('', "Contacts reload: done") except IOError: weechat.prnt( '', "%sIOError: Unable to access %s file" % (csv_file, weechat.prefix("error"))) return weechat.WEECHAT_RC_ERROR return weechat.WEECHAT_RC_OK
def buffer_input_cb(data, buffer, input_data): # ... end_message = "" options = [script_options['screen_name']] if script_options['alt_rt_style']: options.append("alt_rt_style") if script_options['home_replies']: options.append("home_replies") if input_data[0] == ':': if data != "silent": weechat.prnt_date_tags(buffer, 0, "no_highlight", input_data) input_args = input_data.split() command = input_args[0][1:] if command_dict.get(command): input_data = input_data.replace(command,command_dict[command],1) command = command_dict[command] if command == 'd' and tweet_dict.get(input_args[1]): input_data = 'd ' + tweet_dict[input_args[1]] weechat.prnt(buffer, "%sYou deleted the following tweet:" % weechat.prefix("network")) elif command == 'v' and tweet_dict.get(input_args[1]): input_data = 'v ' + tweet_dict[input_args[1]] end_message = "Done" elif command == 'rt' and tweet_dict.get(input_args[1]): end_message = "id" input_data = 'rt ' + tweet_dict[input_args[1]] elif command == 're' and tweet_dict.get(input_args[1]): end_message = "id" input_data = 're ' + tweet_dict[input_args[1]] + " '" + html_escape(input_data[6:]) + "'" elif command == 'new': end_message = "id" if script_options['last_id'] != "": input_data = 'new ' + script_options['last_id'] else: input_data = 'home' elif command == 'home' or command == 'r' or (command == 'favs' and len(input_args) >= 2 and input_args[1].isdigit()): input_data = command if len(input_args) == 3 and tweet_dict.get(input_args[1]) and input_args[2].isdigit(): num = int(input_args[2]) # 200 tweets is the max request limit if num <= 200 and num > 0: input_data += " " + tweet_dict[input_args[1]] + " " + input_args[2] else: input_data += " " + tweet_dict[input_args[1]] elif len(input_args) == 2: if tweet_dict.get(input_args[1]): input_data += " " + tweet_dict[input_args[1]] elif input_args[1].isdigit(): num = int(input_args[1]) # 200 tweets is the max request limit if num <= 200 and num > 0: input_data += " " + input_args[1] end_message = "Done" elif command == 'u' or (command == 'favs' and len(input_args) >= 3): input_data = " ".join(input_args[:2])[1:] if len(input_args) == 4 and tweet_dict.get(input_args[2]) and input_args[3].isdigit(): num = int(input_args[3]) # 200 tweets is the max request limit if num <= 200 and num > 0: input_data += " " + tweet_dict[input_args[2]] + " " + input_args[3] else: input_data += " " + tweet_dict[input_args[2]] elif len(input_args) == 3: if tweet_dict.get(input_args[2]): input_data += " " + tweet_dict[input_args[2]] elif input_args[2].isdigit(): num = int(input_args[2]) # 200 tweets is the max request limit if num <= 200 and num > 0: input_data += " " + input_args[2] end_message = "Done" elif command == 'auth': if len(input_args) == 2: oauth_dance(buffer,input_args[1]) else: oauth_dance(buffer) return weechat.WEECHAT_RC_OK elif command == 'f' or command == 'fo': #L because we are returning a list to be printed later on end_message = "L" if len(input_args) == 3 and tweet_dict.get(input_args[2]): input_data = command + " " + input_args[1] + " " + tweet_dict[input_args[2]] elif len(input_args) == 2: if tweet_dict.get(input_args[1]): input_data = command + " " + script_options['screen_name'] + " " + tweet_dict[input_args[1]] #Your list, not any other users end_message += "Y" else: input_data = input_data[1:] else: input_data = command + " " + script_options['screen_name'] end_message += "Y" if command == 'f': end_message += "Following" else: end_message += "Followers" elif command == 'a': input_data = input_data[1:] end_message = "About" elif command == 'blocks': input_data = input_data[1:] end_message = "LBlock list" elif command == 'fav' and tweet_dict.get(input_args[1]): input_data = 'fav ' + tweet_dict[input_args[1]] weechat.prnt(buffer, "%sYou fave'd the following tweet:" % weechat.prefix("network")) elif command == 'unfav' and tweet_dict.get(input_args[1]): input_data = 'unfav ' + tweet_dict[input_args[1]] weechat.prnt(buffer, "%sYou unfave'd the following tweet:" % weechat.prefix("network")) elif command == 'cnicks': global tweet_nicks_group if tweet_nicks_group[buffer] != "": weechat.nicklist_remove_group(buffer, tweet_nicks_group[buffer]) tweet_nicks_group[buffer] = "" tweet_nicks_group[buffer] = weechat.nicklist_add_group(buffer, "", "Tweet_parse", "weechat.color.nicklist_group", 1) return weechat.WEECHAT_RC_OK elif command == 'help': weechat.command(buffer,"/help twitter") weechat.prnt(buffer, "Exec command /help twitter, check your root buffer") return weechat.WEECHAT_RC_OK elif command == 'clear': weechat.command(buffer,"/buffer clear") return weechat.WEECHAT_RC_OK elif command == 'stream': args = html_escape(input_data[7:]) weechat.prnt(buffer,create_stream("t_stream",args)) return weechat.WEECHAT_RC_OK elif command == 're_home': weechat.prnt(buffer,create_stream("twitter")) return weechat.WEECHAT_RC_OK else: input_data = input_data[1:] end_message = "Done" else: end_message = "id" #esacpe special chars when printing to commandline input_data = 't ' + "'" + html_escape(input_data) + "'" #input_data = 't ' + "'" + html.escape(input_data) + "'" weechat.hook_process("python3 " + SCRIPT_FILE_PATH + " " + script_options["oauth_token"] + " " + script_options["oauth_secret"] + " " + input_data + " " + '"' + str(options) + '"', 10 * 1000, "my_process_cb", str([buffer,end_message])) return weechat.WEECHAT_RC_OK
def shutdown(): for buffer in triggerbotbuffers: weechat.nicklist_remove_group(buffer, triggerbotbuffers[buffer]) return weechat.WEECHAT_RC_OK