def vote(steam_name,player_name,text): regex = re.compile('!vote (?P<id>[0-9]+) (?P<opt>[0-9]+)',re.IGNORECASE) matches = regex.search(text) if matches is not None: res=Db.find_survey(matches.group('id')) if res is not None: survey_id=res.id else: survey_id=None option = matches.group('opt') if Db.option_exists(survey_id,option) is True: choice=matches.group('opt') player=Db.find_player(steam_name=steam_name) steam_id=player.steam_id if player is not None else None player_name=player.name if player is not None else None if steam_id is not None: result=Db.vote(survey_id,choice,steam_id,player_name) if result is True: msg=Lang.get('survey_vote_ok') result=True else: msg=Lang.get('survey_vote_error') result= False else: msg=Lang.get('survey_vote_no_steamid') result= False else: msg=Lang.get('survey_vote_option_not_found').format(matches.group('opt')) result= False else: msg=Lang.get('survey_vote_syntax_error') result= False Rcon.message_steam_name(steam_name,msg) return result
def admin_check_version(steam_name,player_name,text): if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), text) return False res, live_version, steam_version = ServerControl.new_version() if res is True: Rcon.message_steam_name(steam_name,Lang.get('new_version')) return True else: Rcon.message_steam_name(steam_name,Lang.get('no_new_version')) return False
def list_online(steam_name,player_name,text): players = {} for steam_id, p_steam_name in Storage.players_online_steam_name.items(): if steam_id in Storage.players_online_player_name and Storage.players_online_player_name[steam_id]: players[steam_id] = Storage.players_online_player_name[steam_id] else: players[steam_id] = p_steam_name player_list = ", ".join(players.values()) response = Lang.get('chat_players_online').format(len(Storage.players_online_steam_name), player_list) Rcon.message_steam_name(steam_name,response)
def list_online(recipient): players = {} for steam_id, steam_name in Storage.players_online_steam_name.items(): if steam_id in Storage.players_online_player_name and Storage.players_online_player_name[steam_id]: players[steam_id] = Storage.players_online_player_name[steam_id] else: players[steam_id] = steam_name player_list = ", ".join(players.values()) response = Lang.get('chat_players_online').format(len(Storage.players_online_steam_name), player_list) Rcon.message_steam_name(recipient,response)
def last_seen(steam_name,player_name,text): cmdlen = len("!lastseen ") name = text[cmdlen:] player = Db.find_player_wildcard(name) if player is None: response = Lang.get('chat_last_seen_error').format(name) else: date = player.last_seen seconds_ago = int(time.time() - date.timestamp()) ago = time_ago(date.timestamp()) response = Lang.get('chat_last_seen').format(name,ago,date) Rcon.message_steam_name(steam_name,response)
def admin_update_now(steam_name,player_name,text): if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), text) return False res, live_version, steam_version = ServerControl.new_version() if res is True: ServerControl.update_and_restart_server() Rcon.message_steam_name(steam_name,Lang.get('update_restart')) Rcon.broadcast(Lang.get('update_restart'), Rcon.response_callback_response_only) return True else: Rcon.message_steam_name(steam_name,Lang.get('no_new_version')) return False
def last_seen(recipient,text): cmdlen = len("!lastseen ") name = text[cmdlen:] player = Db.find_player_wildcard(name) if player is None: response = Lang.get('chat_last_seen_error').format(name) else: date = player.last_seen seconds_ago = int(time.time() - date.timestamp()) ago = time_ago(date.timestamp()) response = Lang.get('chat_last_seen').format(name,ago,date) Rcon.message_steam_name(recipient,response)
def quote(steam_name,player_name,text): regex = re.compile('!quote (?P<id>[0-9]+)',re.IGNORECASE) matches = regex.search(text) if matches is None: Rcon.message_steam_name(steam_name,Lang.get('quote_error')) return False quote = matches.group('id') result = Db.find_quote(quote) if result is not None: msg = Lang.get('quote_ok').format(quote,result.created,result.name,result.data) Rcon.broadcast(msg, Rcon.response_callback_response_only) return True else: Rcon.message_steam_name(steam_name,Lang.get('quote_not_found').format(quote)) return False
def survey(steam_name,player_name,text): regex = re.compile('!survey (?P<id>[0-9]+)',re.IGNORECASE) matches = regex.search(text) if matches is not None: result=Db.find_survey(matches.group('id')) else: result=Db.find_survey(None) if result is not None: options = Db.find_options(result.id) if options is not None: msg=Lang.get('survey_show').format(result.id,result.question,options,result.id,result.id) else: msg=Lang.get('survey_show_no_options').format(result.id,result.question) Rcon.broadcast(msg,Rcon.response_callback_response_only) return True else: msg=Lang.get('survey_no_found') Rcon.message_steam_name(steam_name,msg) return False
def admin_filter_remove(steam_name,player_name,text): if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), text) return False regex = re.compile('!admin_filter_remove (?P<words>[a-z ]+)',re.IGNORECASE) matches = regex.search(text) if matches is None: Rcon.message_steam_name(steam_name,Lang.get('chat_filter_remove_no_word')) return False words = matches.group('words') words = words.split() result=None for word in words: res = Db.remove_word(word) if res is False: res = Lang.get('chat_filter_remove_word_does_not_exists').format(word) else: res = Lang.get('unauthorized').format(word) if result is None: result = Lang.get('chat_filter_result').format(res) else: result = "{}, {}".format(result,res) Rcon.message_steam_name(steam_name,result)
def admin_restart(steam_name,player_name,text): if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), text) return False if text.lower().strip() == '!admin_restart now': Rcon.message_steam_name(steam_name,Lang.get('issue_restart_now')) Rcon.broadcast(Lang.get('restarting'),Rcon.callback_restart()) return True regex = re.compile('!admin_restart (?P<minutes>[\d]+)',re.IGNORECASE) matches = regex.search(text) if matches is None: Rcon.message_steam_name(steam_name,Lang.get('admin_restart_failed')) return False minutes = matches.group('minutes') result, err = Rcon.delayed_restart(minutes) if not result: Rcon.message_steam_name(steam_name,'ERROR: {}'.format(err)) return False Rcon.message_steam_name(steam_name,Lang.get('issue_restart')) return True
def admin_start_survey(steam_name,player_name,text): if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), text) return False regex=re.compile('!admin_start_survey (?P<id_survey>[0-9]+)',re.IGNORECASE) matches = regex.search(text) if matches is None: Rcon.message_steam_name(steam_name,Lang.get('survey_start_noid')) return False id_survey=matches.group('id_survey') result=False result=Db.start_survey(id_survey) if result is True: Rcon.message_steam_name(steam_name,Lang.get('survey_start_ok').format(id_survey,id_survey)) else: Rcon.message_steam_name(steam_name,Lang.get('survey_start_error').format(id_survey))
def admin_survey_add(steam_name,player_name,text): if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), text) return False regex=re.compile('!admin_survey_add (?P<question>[a-zA-Z0-9 ?]+)',re.IGNORECASE) matches = regex.search(text) if matches is None: Rcon.message_steam_name(steam_name,Lang.get('survey_no_question')) return False question=matches.group('question') result = None result = Db.add_survey(question) if result is not None: Rcon.message_steam_name(steam_name,Lang.get('survey_created').format(result,result)) else: Rcon.message_steam_name(steam_name,Lang.get('survey_add_error'))
def help(steam_name,player_name,text): Rcon.message_steam_name(steam_name,Lang.get('chat_help'))
def next_restart(steam_name,player_name,text): seconds_left, str_countdown = Rcon.get_next_restart_string() response = 'Next restart: {}'.format(str_countdown) Rcon.message_steam_name(steam_name,response)
def parse(steam_name,player_name,text): #recipient = Db.find_player(player_name=player_name) cmd = ChatCommands._find_cmd(text) if cmd is False: debug_out(Lang.get('not_a_command').format(text),level=1) return False cmd = cmd.lower() debug_out('Processing chat command: ',cmd,level=1) if cmd == 'lastseen': ChatCommands.last_seen(steam_name,text) return True elif cmd == 'online': ChatCommands.list_online(steam_name) return True elif cmd == 'admin_restart': if not Rcon.is_admin(steam_name=steam_name): out(Lang.get('unauthorized'), cmd) return False if text.lower().strip() == '!admin_restart now': Rcon.message_steam_name(steam_name,Lang.get('issue_restart_now')) Rcon.broadcast(Lang.get('restarting')) ServerControl.restart_server() return True regex = re.compile('!admin_restart (?P<minutes>[\d]+)',re.IGNORECASE) matches = regex.search(text) if matches is None: Rcon.message_steam_name(steam_name,Lang.get('admin_restart_failed')) return False minutes = matches.group('minutes') result, err = Rcon.delayed_restart(minutes) if not result: Rcon.message_steam_name(steam_name,'ERROR: {}'.format(err)) return False Rcon.message_steam_name(steam_name,Lang.get('issue_restart')) return True elif cmd == 'next_restart': seconds_left, str_countdown = Rcon.get_next_restart_string() response = 'Next restart: {}'.format(str_countdown) Rcon.message_steam_name(steam_name,response) return True elif cmd == 'help': Rcon.message_steam_name(steam_name,Lang.get('chat_help')) return True return False