Best Python code snippet using localstack_python
teamtalk mafia bot.py
Source:teamtalk mafia bot.py
1#!/usr/bin/python32# -*- coding: utf-8 -*-3import teamtalk, random, os, configparser, sys, threading, win32gui, win32con, ctypes, winsound4ctypes.windll.kernel32.SetConsoleTitleW("teamtalk mafia bot-v2.0")5t = teamtalk.TeamTalkServer()6newRoles = []7god_role_list = []8players = []9numbers = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25"]10full_mafia =["پدر Ø®ÙاÙدÙ", "دکتر ÙÙکتÙر", "Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù1", "Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù2", 'دزد', 'Ùاتاشا', 'Ø´ÙرÙÙد ', 'ÙاتÙ', 'ØرÙÙ Ø§Û Ù
اÙÛا', 'ترÙرÛست', 'Ù
ذاکرÙâÚ©ÙÙدÙ', 'سÙ
', 'دارÙساز', 'شب خسب', 'بازجÙ', 'خرابکار', 'ÛاکÙزا', 'اÙسÙÙگر', 'گرÙگاÙÚ¯Ûر', 'Ø¢Ù
Ù¾Ù٠زÙ', 'Ù
رد ÙÙرÙ
اÙ', ]11p_mafia = []12r_mafia = []13send_to_mafia_players = []14normal_votelists = set()15normal_voteUserList = set()16card_name = ["Ø´ÙÛÚ© ÙÙاÛÛ", "Ù
سÛر سبز", "بÛØ®ÙابÛ", "درÙغ سÛزدÙ", "Ø°Ù٠زÛبا", "Ùرش ÙرÙ
ز"]17card_number = ['1', '2', '3', '4', '5', '6']18hidden_main_votelists = []19hidden_votelists = set()20hidden_voteUserList = set()21hidden_vote_list_result = []22timeUserList = set()23@t.subscribe("messagedeliver")24def roles(server, params):25 global role_content26 if params["type"] != teamtalk.USER_MSG:27 return28 hwnd = win32gui.GetForegroundWindow()29 win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)30 role_content = params["content"]31 role_user = t.get_user(params["srcuserid"])32 nickname = role_user["nickname"]33 if role_user.get('chanid') == int(chanid):34 if nickname == " god" and role_content == 'b' or nickname == " god" and role_content == 'Ø°':35 t.broadcast_message('Ù
اÙÛا بازÙا بÛاÛÛد بازÛ.')36 if nickname == " god" and role_content == "شرÙع" or nickname == " god" and role_content == "start":37 t.channel_message('Ø¨Ù Ø¨Ø§Ø²Û Ø´Ø¨ÙØ§Û Ù
اÙÛا Ø®ÙØ´ اÙÙ
دÛد.')38 channel_users = t.get_users_in_channel(int(chanid))39 for user in channel_users:40 new_user = user['nickname']41 for number in numbers:42 if number in new_user:43 players.append(new_user)44 players.sort()45 if len(players) < 8:46 t.channel_message('تعداد بازÛÚ©ÙÙا Ú©Ù
تر از 8 ÙÙر Ù
Ûباشد.')47 else:48 t.channel_message(f"{len(players)} ÙÙر در اÛÙ Ø¨Ø§Ø²Û Ø´Ø±Ú©Øª دارÙد.")49 t.user_message(" god", '12 ÙÙØ´ استاÙدارد در ÙÛست ÙجÙد دارد.\nØ¢Ûا Ù
اÛÙ ÙستÛد ÙÙØ´ جدÛØ¯Û Ø±Ø§ ب٠ÙÛست ÙÙØ´ Ùا اضاÙÙ Ú©ÙÛدØ\nبÙÙ Ûا Ø®Ûر ÙÙشت٠٠بÙرستÛد.')50 @t.subscribe('messagedeliver')51 def role_question(server, params):52 if params['type'] != teamtalk.USER_MSG:53 return54 role_question_content = params['content']55 role_question_user = t.get_user(params["srcuserid"])56 nickname = role_question_user["nickname"]57 if role_question_user.get('chanid') == int(chanid):58 if nickname == " god" and role_question_content == "بÙÙ":59 t.user_message(' god', 'ÙÙØ´ Ùا ر٠با گذاشت٠ÙÛرگÙÙ Ûا کاÙ
ا بÛÙØ´ÙÙ Ùارد Ú©ÙÛد.\nتÙج٠داشت٠باشÛد اگ٠ÙÙØ´ÙØ§Û Ùارد شد٠بدÙÙ ÙÛرگÙÙ Ûا کاÙ
ا باشÙد ÛÚ© ÙÙØ´ Øساب Ø®ÙاÙÙد شد.')60 @t.subscribe("messagedeliver")61 def add_role(server, params):62 if params['type'] != teamtalk.USER_MSG:63 return64 add_role_content = params['content']65 extra_list_roles = ["پدر Ø®ÙاÙدÙ", "دکتر ÙÙکتÙر", "Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù1", "Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù2", "دکتر", "رÙاÙپزشک", "اÙسÙاÛÙ¾Ùر Ûا ØرÙ٠اÛ", "کارآگاÙ", "Ø´Ùردار", "جا٠سخت", "Ø´ÙرÙÙد سادÙ1", "Ø´ÙرÙÙد سادÙ2"]66 if not add_role_content == "بÙÙ" and not add_role_content == "ÙÙØ´":67 for i in add_role_content.split(','):68 extra_list_roles .append(i)69 if len(extra_list_roles) == len(players):70 t.user_message(' god', 'با ارسا٠کÙÙ
Ù ÙÙØ´Ø ÙÙØ´ Ùا را Ø¨Ø±Ø§Û ÙÙ
٠ارسا٠کÙÛد. ')71 @t.subscribe("messagedeliver")72 def unconstant_role_sending(server, params):73 if params['type'] != teamtalk.USER_MSG:74 return75 unconstant_role_content = params['content']76 unconstant_role_user = t.get_user(params["srcuserid"])77 nickname = unconstant_role_user["nickname"]78 if unconstant_role_user.get('chanid') == int(chanid):79 if nickname == " god" and unconstant_role_content == "ÙÙØ´":80# اÙتخاب ÙÙØ´ ب٠صÙرت رÙÙدÙÙ
81 for i in range(0, len(extra_list_roles)):82# ØØ°Ù ÙÙØ´ اÙتخاب شد٠از ÙÛست اصÙÛ Ø¨Ø±Ø§Û Ø¬ÙÙÚ¯ÛØ±Û Ø§Ø² تکرار83 rand = random.choice(extra_list_roles)84 newRoles.append(rand)85 extra_list_roles.remove(rand)86 for i in range(0, len(players)):87 t.user_message(players[i], f"{players[i]} در ÙÙØ´ {newRoles[i]}")88 godlist = f"{players[i]} در ÙÙØ´ {newRoles[i]}"89 god_role_list.append(godlist)90 t.user_message(" god", '\n'.join(god_role_list[0:3]))91 t.user_message(" god", '\n'.join(god_role_list[3:6]))92 t.user_message(" god", '\n'.join(god_role_list[6:9]))93 t.user_message(" god", '\n'.join(god_role_list[9:12]))94 t.user_message(" god", '\n'.join(god_role_list[12:15]))95 if len(players) >= 16:96 t.user_message(" god", '\n'.join(god_role_list[15:18]))97 if len(players) >= 19:98 t.user_message(" god", '\n'.join(god_role_list[18:21]))99 if len(players) >= 22:100 t.user_message(" god", '\n'.join(god_role_list[21:25]))101 t.channel_message('پاÛا٠ارسا٠ÙÙØ´')102 t.change_status(0, 'پاÛا٠ارسا٠ÙÙØ´')103 t.user_message(" god", 'با ارسا٠کÙÙ
Ù Ù
اÙÛا Ù
اÙÛاÙا ر٠بÙÙ
Ù
عرÙÛ Ú©ÙÛد.')104 @t.subscribe("messagedeliver")105 def mafia_role_sending(server, params):106 if params['type'] != teamtalk.USER_MSG:107 return108 mafia_role_content = params['content']109 mafia_role_user = t.get_user(params["srcuserid"])110 nickname = mafia_role_user["nickname"]111 if mafia_role_user.get('chanid') == int(chanid):112 if nickname == " god" and mafia_role_content == "Ù
اÙÛا":113 #ارسا٠ÙÙØ´ ÙØ§Û Ù
اÙÛا ب٠Ù
اÙÛاÙا114 doovr = 0115 for i in newRoles:116 if i in full_mafia:117 r_mafia.append(i)118 p_mafia.append(players[doovr])119 doovr += 1120 len_p_mafia = len(p_mafia)121 dict1 = {122 }123 tupl_list = []124 for i in range(0, len_p_mafia):125 list0 = []126 list0.append(p_mafia[i])127 list0.append(r_mafia[i])128 tp = tuple(list0)129 tupl_list.append(tp)130 list0.clear131 for p in p_mafia:132 dict1[p] = []133 for r in tupl_list:134 if p in r:135 continue136 dict1[p].append(r)137 for key, value in dict1.items():138 for i in range(0, len_p_mafia - 1):139 m_role = f"{value[i][0]} در ÙÙØ´ {value[i][1]}"140 send_to_mafia_players.append(m_role)141 t.user_message(key, '\n'.join(send_to_mafia_players))142 send_to_mafia_players.clear()143 newRoles.clear()144 players.clear()145 t.channel_message('Ù
اÙÛا Ùا بÙÙ
Ù
عرÙÛ Ø´Ø¯Ùد.')146 t.change_status(0, 'Ù
اÙÛا Ùا بÙÙ
Ù
عرÙÛ Ø´Ø¯Ùد.')147 else:148 @t.subscribe("messagedeliver")149 def errorContent(server, params):150 if params['type'] != teamtalk.USER_MSG:151 return152 error_content = params['content']153 error_user = t.get_user(params["srcuserid"])154 nickname = error_user["nickname"]155 if error_user.get('chanid') == int(chanid):156 if nickname == " god" and not error_content == "Ù
اÙÛا":157 t.user_message(' god', 'تعداد ÙÙØ´Ùا با تعداد Ø¨Ø§Ø²Û Ú©ÙÙا ÛÚ©Û ÙÛست')158 else:159 pass160 if nickname == " god" and role_question_content == "Ø®Ûر":161 if len(players) >= 13:162 t.user_message(' god', 'تعداد بازÛÚ©ÙÙا بÛشتر از Û±Û² ÙÙر Ù
Ûباشد.')163 else:164 list_roles = ["پدر Ø®ÙاÙدÙ", "دکتر ÙÙکتÙر", "Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù1", "Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù2", "دکتر", "رÙاÙپزشک", "اÙسÙاÛÙ¾Ùر Ûا ØرÙ٠اÛ", "کارآگاÙ", "Ø´Ùردار", "جا٠سخت", "Ø´ÙرÙÙد سادÙ1", "Ø´ÙرÙÙد سادÙ2"]165 new_roles =[]166 t.user_message(' god', 'با ارسا٠کÙÙ
Ù ÙÙØ´Ø ÙÙØ´ Ùا را Ø¨Ø±Ø§Û ÙÙ
٠ارسا٠کÙÛد. ')167 @t.subscribe("messagedeliver")168 def constant_role_sending(server, params):169 if params['type'] != teamtalk.USER_MSG:170 return171 constant_role_content = params['content']172 try:173 if len(players) < 12:174 list_roles.remove('Ø´ÙرÙÙد سادÙ2')175 if len(players) < 11:176 list_roles.remove("Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù2")177 if len(players) < 10:178 list_roles.remove("Ø´ÙرÙÙد سادÙ1")179 if len(players) < 9:180 list_roles.remove("Ù
اÙÛØ§Û Ø³Ø§Ø¯Ù1")181 except:182 pass183 constant_role_user = t.get_user(params["srcuserid"])184 nickname = constant_role_user["nickname"]185 if constant_role_user.get('chanid') == int(chanid):186 if nickname == " god" and constant_role_content == "ÙÙØ´":187# اÙتخاب ÙÙØ´ ب٠صÙرت رÙÙدÙÙ
188 for i in range(0, len(list_roles)):189# ØØ°Ù ÙÙØ´ اÙتخاب شد٠از ÙÛست اصÙÛ Ø¨Ø±Ø§Û Ø¬ÙÙÚ¯ÛØ±Û Ø§Ø² تکرار190 rand = random.choice(list_roles)191 new_roles.append(rand)192 list_roles.remove(rand)193 for i in range(0, len(players)):194 t.user_message(players[i], f"{players[i]} در ÙÙØ´ {new_roles[i]}")195 godlist = f"{players[i]} در ÙÙØ´ {new_roles[i]}"196 god_role_list.append(godlist)197 t.user_message(" god", '\n'.join(god_role_list[0:3]))198 t.user_message(" god", '\n'.join(god_role_list[3:6]))199 t.user_message(" god", '\n'.join(god_role_list[6:9]))200 if len(players) >= 10:201 t.user_message(" god", '\n'.join(god_role_list[9:12]))202 t.channel_message('پاÛا٠ارسا٠ÙÙØ´')203 t.change_status(0, 'پاÛا٠ارسا٠ÙÙØ´')204 t.user_message(" god", 'با ارسا٠کÙÙ
Ù Ù
اÙÛا Ù
اÙÛاÙا ر٠بÙÙ
Ù
عرÙÛ Ú©ÙÛد.')205 @t.subscribe("messagedeliver")206 def mafia_role_sending(server, params):207 if params['type'] != teamtalk.USER_MSG:208 return209 mafia_role_content = params['content']210 mafia_role_user = t.get_user(params["srcuserid"])211 nickname = mafia_role_user["nickname"]212 if mafia_role_user.get('chanid') == int(chanid):213 if nickname == " god" and mafia_role_content == "Ù
اÙÛا":214 #ارسا٠ÙÙØ´ ÙØ§Û Ù
اÙÛا ب٠Ù
اÙÛاÙا215 doovr = 0216 for i in new_roles:217 if i in full_mafia:218 r_mafia.append(i)219 p_mafia.append(players[doovr])220 doovr += 1221 len_p_mafia = len(p_mafia)222 dict1 = {223 }224 tupl_list = []225 for i in range(0, len_p_mafia):226 list0 = []227 list0.append(p_mafia[i])228 list0.append(r_mafia[i])229 tp = tuple(list0)230 tupl_list.append(tp)231 list0.clear232 for p in p_mafia:233 dict1[p] = []234 for r in tupl_list:235 if p in r:236 continue237 dict1[p].append(r)238 for key, value in dict1.items():239 for i in range(0, len_p_mafia - 1):240 m_role = f"{value[i][0]} در ÙÙØ´ {value[i][1]}"241 send_to_mafia_players.append(m_role)242 t.user_message(key, '\n'.join(send_to_mafia_players))243 send_to_mafia_players.clear()244 new_roles.clear()245 players.clear()246 t.channel_message('Ù
اÙÛا Ùا بÙÙ
Ù
عرÙÛ Ø´Ø¯Ùد.')247 t.change_status(0, 'Ù
اÙÛا Ùا بÙÙ
Ù
عرÙÛ Ø´Ø¯Ùد.')248 @t.subscribe('messagedeliver')249 def roles_list(server, params):250 if params["type"] != teamtalk.USER_MSG:251 return252 roles_list_content = params["content"]253 roles_list_user = t.get_user(params["srcuserid"])254 nickname = roles_list_user["nickname"]255 if roles_list_user.get('chanid') == int(chanid):256 if nickname == " god" and role_content == "rl" or nickname == " god" and role_content == "ÙÙ
":257 if '\n'.join(god_role_list) == '':258 t.user_message(' god', 'ÙÙÙز ÙÙØ´Ùا تعÛÛÙ ÙشدÙ')259 else:260 t.user_message(' god', '\n'.join(god_role_list))261 else:262 t.user_message(role_user, "بÛرÙ٠از کاÙا٠ÙÙ
ÛتÙاÙÛد Ù¾ÛاÙ
بدÙÛد.")263@t.subscribe("messagedeliver")264def end(server, params):265 if params["type"] != teamtalk.USER_MSG:266 return267 end_content = params["content"]268 end_user = t.get_user(params["srcuserid"])269 nickname = end_user["nickname"]270 if end_user.get('chanid') == int(chanid):271 if nickname == " god" and end_content == "f" or nickname == " god" and end_content == "ب":272 t.channel_message('با تشکر از Ø´Ù
ا بخاطر بازÛ\nØ¨Ø§Ø²Û ØªÙ
ÙÙ
شد.\nبرÙ
ÙØ§Ø³Ù Ø¨Ø§Ø²Û Ø¨Ø¹Ø¯Û Ø¨ÛاÙ
.')273 os.execl(sys.executable, sys.executable, *sys.argv)274@t.subscribe("messagedeliver")275def normal_time(server, params):276 if params["type"] != teamtalk.USER_MSG:277 return278 def normal_time_end_message():279 normal_time.thread_run = False280 t.channel_message(f"پاÛا٠زÙ
ا٠صØبت بازÛÚ©Ù {''.join(timeUserList)} 60 ثاÙÛÙ")281 t.change_status(0, f"پاÛا٠زÙ
ا٠صØبت بازÛÚ©Ù {''.join(timeUserList)} 60 ثاÙÛÙ")282 normal_time_content = params["content"].lower()283 normal_time_users = t.get_users_in_channel(int(chanid))284 normal_time_user = t.get_user(params['srcuserid'])285 if normal_time_user.get('chanid') == int(chanid):286 for normalUserNumber in numbers:287 if " god" in normal_time_user['nickname'] and not normal_time.thread_run and normal_time_content == f"t {normalUserNumber}" or " god" in normal_time_user['nickname'] and not normal_time.thread_run and normal_time_content == f"Ù {normalUserNumber}" or " god" in normal_time_user['nickname'] and not normal_time.thread_run and normal_time_content == f"t{normalUserNumber}" or " god" in normal_time_user['nickname'] and not normal_time.thread_run and normal_time_content == f"Ù{normalUserNumber}":288 timeUserList.clear()289 for normal_user in normal_time_users:290 normalUser = normal_user['nickname']291 if normalUserNumber in normalUser:292 t.channel_message(f"شرÙع زÙ
ا٠صØبت Ø¨Ø±Ø§Û {normalUser} 60 ثاÙÛÙ")293 t.change_status(0, f"شرÙع زÙ
ا٠صØبت Ø¨Ø±Ø§Û {normalUser} 60 ثاÙÛÙ")294 timeUserList.add(normalUser)295 normal_time.thread = threading.Timer(60, normal_time_end_message)296 normal_time.thread.daemon = True297 normal_time.thread.start()298 normal_time.thread_run = True299 elif " god" in normal_time_user['nickname'] and normal_time.thread_run and normal_time_content == f"t {normalUserNumber}" or " god" in normal_time_user['nickname'] and normal_time.thread_run and normal_time_content == f"Ù {normalUserNumber}" or " god" in normal_time_user['nickname'] and normal_time.thread_run and normal_time_content == f"t{normalUserNumber}" or " god" in normal_time_user['nickname'] and normal_time.thread_run and normal_time_content == f"Ù{normalUserNumber}":300 t.user_message(' god', '60 ثاÙÛÙ ÙÙÙز تÙ
ÙÙ
ÙشدÙ\nÙ
ÛتÙÙÛ tc بزÙÛ ØªØ§ Ùغ٠بشÙ')301 if " god" in normal_time_user['nickname'] and normal_time.thread_run and normal_time_content == 'tc' or " god" in normal_time_user['nickname'] and normal_time.thread_run and normal_time_content == 'Ùز':302 normal_time.thread.cancel()303 normal_time.thread_run = False304 t.channel_message(f"Ùغ٠زÙ
ا٠صØبت بازÛÚ©Ù {''.join(timeUserList)} 60 ثاÙÛÙ")305 t.change_status(0, f"Ùغ٠زÙ
ا٠صØبت بازÛÚ©Ù {''.join(timeUserList)} 60 ثاÙÛÙ")306 elif " god" in normal_time_user['nickname'] and not normal_time.thread_run and normal_time_content == 'tc' or " god" in normal_time_user['nickname'] and not normal_time.thread_run and normal_time_content == 'Ùز':307 t.user_message(' god', '60 ثاÙÛÙ Ùعا٠ÙÛست.')308normal_time.thread = 't'309normal_time.thread_run = False310@t.subscribe("messagedeliver")311def challenge_time(server, params):312 if params["type"] != teamtalk.USER_MSG:313 return314 def challenge_time_end_message():315 challenge_time.thread_run = False316 t.channel_message(f"پاÛا٠زÙ
ا٠ÚاÙØ´ بازÛÚ©Ù {''.join(timeUserList)} 30 ثاÙÛÙ")317 t.change_status(0, f"پاÛا٠زÙ
ا٠ÚاÙØ´ بازÛÚ©Ù {''.join(timeUserList)} 30 ثاÙÛÙ")318 challenge_time_content = params["content"].lower()319 challenge_time_users = t.get_users_in_channel(int(chanid))320 challenge_time_user = t.get_user(params['srcuserid'])321 if challenge_time_user.get('chanid') == int(chanid):322 for normalUserNumber in numbers:323 if " god" in challenge_time_user['nickname'] and not challenge_time.thread_run and challenge_time_content == f"ch {normalUserNumber}" or " god" in challenge_time_user['nickname'] and not challenge_time.thread_run and challenge_time_content == f"زا {normalUserNumber}" or " god" in challenge_time_user['nickname'] and not challenge_time.thread_run and challenge_time_content == f"ch{normalUserNumber}" or " god" in challenge_time_user['nickname'] and not challenge_time.thread_run and challenge_time_content == f"زا{normalUserNumber}":324 timeUserList.clear()325 for normal_user in challenge_time_users:326 normalUser = normal_user['nickname']327 if normalUserNumber in normalUser:328 t.channel_message(f"شرÙع زÙ
ا٠ÚاÙØ´ Ø¨Ø±Ø§Û {normalUser} 30 ثاÙÛÙ")329 t.change_status(0, f"شرÙع زÙ
ا٠ÚاÙØ´ Ø¨Ø±Ø§Û {normalUser} 30 ثاÙÛÙ")330 timeUserList.add(normalUser)331 challenge_time.thread = threading.Timer(30, challenge_time_end_message)332 challenge_time.thread.daemon = True333 challenge_time.thread.start()334 challenge_time.thread_run = True335 elif " god" in challenge_time_user['nickname'] and challenge_time.thread_run and challenge_time_content == f"ch {normalUserNumber}" or " god" in challenge_time_user['nickname'] and challenge_time.thread_run and challenge_time_content == f"زا {normalUserNumber}" or " god" in challenge_time_user['nickname'] and challenge_time.thread_run and challenge_time_content == f"ch{normalUserNumber}" or " god" in challenge_time_user['nickname'] and challenge_time.thread_run and challenge_time_content == f"زا{normalUserNumber}":336 t.user_message(' god', '30 ثاÙÛÙ ÙÙÙز تÙ
ÙÙ
ÙشدÙ\nÙ
ÛتÙÙÛ cc بزÙÛ ØªØ§ Ùغ٠بشÙ')337 if " god" in challenge_time_user['nickname'] and challenge_time.thread_run and challenge_time_content == "cc" or " god" in challenge_time_user['nickname'] and challenge_time.thread_run and challenge_time_content == "زز":338 challenge_time.thread.cancel()339 challenge_time.thread_run = False340 t.channel_message(f"Ùغ٠زÙ
ا٠ÚاÙØ´ بازÛÚ©Ù {''.join(timeUserList)} 30 ثاÙÛÙ.")341 t.change_status(0, f"Ùغ٠زÙ
ا٠ÚاÙØ´ بازÛÚ©Ù {''.join(timeUserList)} 30 ثاÙÛÙ.")342 elif " god" in challenge_time_user['nickname'] and not challenge_time.thread_run and challenge_time_content == "cc" or " god" in challenge_time_user['nickname'] and not challenge_time.thread_run and challenge_time_content == "زز":343 t.user_message(' god', '30 ثاÙÛÙ Ùعا٠ÙÛست.')344challenge_time.thread = 'cht'345challenge_time.thread_run = False346@t.subscribe("messagedeliver")347def defense_time(server, params):348 if params["type"] != teamtalk.USER_MSG:349 return350 def defense_time_end_message():351 defense_time.thread_run = False352 t.channel_message(f"پاÛا٠زÙ
ا٠دÙاع بازÛÚ©Ù {''.join(timeUserList)} 90 ثاÙÛÙ.")353 t.change_status(0, f"پاÛا٠زÙ
ا٠دÙاع بازÛÚ©Ù {''.join(timeUserList)} 90 ثاÙÛÙ.")354 defense_time_content = params["content"].lower()355 defense_time_users = t.get_users_in_channel(int(chanid))356 defense_time_user = t.get_user(params['srcuserid'])357 if defense_time_user.get('chanid') == int(chanid):358 for normalUserNumber in numbers:359 if " god" in defense_time_user['nickname'] and not defense_time.thread_run and defense_time_content == f"d {normalUserNumber}" or " god" in defense_time_user['nickname'] and not defense_time.thread_run and defense_time_content == f"Û {normalUserNumber}" or " god" in defense_time_user['nickname'] and not defense_time.thread_run and defense_time_content == f"d{normalUserNumber}" or " god" in defense_time_user['nickname'] and not defense_time.thread_run and defense_time_content == f"Û{normalUserNumber}":360 timeUserList.clear()361 for normal_user in defense_time_users:362 normalUser = normal_user['nickname']363 if normalUserNumber in normalUser:364 t.channel_message(f"شرÙع زÙ
ا٠دÙاع Ø¨Ø±Ø§Û {normalUser} 90 ثاÙÛÙ.")365 t.change_status(0, f"شرÙع زÙ
ا٠دÙاع Ø¨Ø±Ø§Û {normalUser} 90 ثاÙÛÙ.")366 timeUserList.add(normalUser)367 defense_time.thread = threading.Timer(90, defense_time_end_message)368 defense_time.thread.daemon = True369 defense_time.thread.start()370 defense_time.thread_run = True371 elif " god" in defense_time_user['nickname'] and defense_time.thread_run and defense_time_content == f"d {normalUserNumber}" or " god" in defense_time_user['nickname'] and defense_time.thread_run and defense_time_content == f"Û {normalUserNumber}" or " god" in defense_time_user['nickname'] and defense_time.thread_run and defense_time_content == f"d{normalUserNumber}" or " god" in defense_time_user['nickname'] and defense_time.thread_run and defense_time_content == f"Û{normalUserNumber}":372 t.user_message(' god', '90 ثاÙÛÙ ÙÙÙز تÙ
ÙÙ
ÙشدÙ\nÙ
ÛتÙÙÛ dc بزÙÛ ØªØ§ Ùغ٠بشÙ')373 if " god" in defense_time_user['nickname'] and defense_time.thread_run and defense_time_content == "dc" or " god" in defense_time_user['nickname'] and defense_time.thread_run and defense_time_content == "Ûز":374 defense_time.thread.cancel()375 defense_time.thread_run = False376 t.channel_message(f"Ùغ٠زÙ
ا٠دÙاع بازÛÚ©Ù {''.join(timeUserList)} 90 ثاÙÛÙ.")377 t.change_status(0, f"Ùغ٠زÙ
ا٠دÙاع بازÛÚ©Ù {''.join(timeUserList)} 90 ثاÙÛÙ.")378 elif " god" in defense_time_user['nickname'] and not defense_time.thread_run and defense_time_content == "dc" or " god" in defense_time_user['nickname'] and not defense_time.thread_run and defense_time_content == "Ûز":379 t.user_message(' god', '90 ثاÙÛÙ Ùعا٠ÙÛست.')380defense_time.thread = 'd'381defense_time.thread_run = False382@t.subscribe("messagedeliver")383def normal_vote(server, params):384 if params["type"] != teamtalk.USER_MSG:385 return386 def normal_vote_end_message():387 normal_vote.thread_run = False388 if len(normal_votelists) == 0:389 t.channel_message(f"{''.join(normal_voteUserList)} {len(normal_votelists)} رأÛ.")390 t.user_message(' god', f"{''.join(normal_voteUserList)} {len(normal_votelists)} رأÛ.")391 t.change_status(0, f"{''.join(normal_voteUserList)} {len(normal_votelists)} رأÛ.")392 else:393 t.channel_message(f"{''.join(normal_voteUserList)} {len(normal_votelists)} رأÛ.\nآرا: {' '.join(normal_votelists)}")394 t.user_message(' god', f"{''.join(normal_voteUserList)} {len(normal_votelists)} رأÛ.\nآرا: {' '.join(normal_votelists)}")395 t.change_status(0, f"{''.join(normal_voteUserList)} {len(normal_votelists)} رأÛ.\nآرا: {' '.join(normal_votelists)}")396 normal_vote_content = params["content"].lower()397 normal_vote_users = t.get_users_in_channel(int(chanid))398 normal_vote_user = t.get_user(params['srcuserid'])399 if normal_vote_user.get('chanid') == int(chanid):400 for normalVoteUserNumber in numbers:401 if "god" in normal_vote_user['nickname'] and not normal_vote.thread_run and normal_vote_content == f"v {normalVoteUserNumber}" or "god" in normal_vote_user['nickname'] and not normal_vote.thread_run and normal_vote_content == f"ر {normalVoteUserNumber}" or "god" in normal_vote_user['nickname'] and not normal_vote.thread_run and normal_vote_content == f"v{normalVoteUserNumber}" or "god" in normal_vote_user['nickname'] and not normal_vote.thread_run and normal_vote_content == f"ر{normalVoteUserNumber}":402 normal_votelists.clear()403 normal_voteUserList.clear()404 for vote_user in normal_vote_users:405 voteUser = vote_user['nickname']406 if normalVoteUserNumber in voteUser:407 t.channel_message(f"شرÙع Ø±Ø£Û Ú¯ÛØ±Û {voteUser}")408 t.change_status(0, f"شرÙع Ø±Ø£Û Ú¯ÛØ±Û {voteUser}")409 normal_voteUserList.add(voteUser)410 normal_vote.thread = threading.Timer(4, normal_vote_end_message)411 normal_vote.thread.daemon = True412 normal_vote.thread.start()413 normal_vote.thread_run = True414 @t.subscribe("messagedeliver")415 def vote(server, params):416 if params["type"] != teamtalk.CHANNEL_MSG:417 return418 hwnd = win32gui.GetForegroundWindow()419 win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)420 channel_user = t.get_user(params['srcuserid'])421 new_user = channel_user['nickname']422 if new_user:423 for vote_user_number in numbers:424 if vote_user_number in new_user:425 normal_votelists.add(new_user)426normal_vote.thread = 'nv'427normal_vote.thread_run = False428@t.subscribe("messagedeliver")429def hidden_vote(server, params):430 if params["type"] != teamtalk.USER_MSG:431 return432 def hidden_vote_end_message():433 hidden_vote.thread = False434 if len(hidden_votelists) == 0:435 t.user_message(' god', f"{''.join(hidden_voteUserList)} {len(hidden_votelists)} رأÛ.")436 t.channel_message(f"پاÛØ§Ù Ø±Ø£Û Ù
Ø®ÙÛ {''.join(hidden_voteUserList)}")437 t.change_status(0, f"پاÛØ§Ù Ø±Ø£Û Ù
Ø®ÙÛ {''.join(hidden_voteUserList)}")438 god_vote_list = f"{''.join(hidden_voteUserList)} {len(hidden_votelists)} رأÛ."439 hidden_vote_list_result.append(''.join(god_vote_list))440 else:441 t.user_message(' god', f"{''.join(hidden_voteUserList)} {len(hidden_votelists)} رأÛ.\nآرآ: {''.join(hidden_votelists)}")442 t.channel_message(f"پاÛØ§Ù Ø±Ø£Û Ù
Ø®ÙÛ {''.join(hidden_voteUserList)}")443 t.change_status(0, f"پاÛØ§Ù Ø±Ø£Û Ù
Ø®ÙÛ {''.join(hidden_voteUserList)}")444 god_vote_list = f"{''.join(hidden_voteUserList)} {len(hidden_votelists)} رأÛ."445 hidden_vote_list_result.append(''.join(god_vote_list))446 hidden_vote_content = params["content"].lower()447 hidden_vote_users = t.get_users_in_channel(int(chanid))448 hidden_vote_user = t.get_user(params['srcuserid'])449 if hidden_vote_user.get('chanid') == int(chanid):450 if "god" in hidden_vote_user['nickname'] and hidden_vote_content == "Ù
Ø®ÙÛ":451 t.user_message(' god', 'Ø´Ù
ار٠بازÛÚ©ÙÙاÛÛ Ú©Ù Ø§ÙÙ
Ø¯Ù ØªÙ Ø±Ø£Û Ù
Ø®ÙÛ Ø¨Ø§ گذاشت٠ÙاصÙ٠بÛÙØ´ÙÙ Ùارد Ú©ÙÛد\nاÛ٠کار ر٠Ùاس٠اÛÙک٠ب٠ÙÙ
دÛÚ¯Ù ÙتÙÙÙ Ø±Ø£Û Ø¨ÙدÙ٠اÙجاÙ
Ù
ÛدÛ.\nبعدش Ø´Ù
ار٠ÙÙر اÙ٠ر٠Ùارد بک٠٠بÙÙ
Û٠ترتÛب اداÙ
٠بدÙ.')452 if "god" in hidden_vote_user['nickname'] and hidden_vote_content:453 for i in hidden_vote_content.split():454 if i == "start":455 continue456 if i == "Ù
Ø®ÙÛ":457 continue458 if i == "h":459 continue460 hidden_main_votelists.append(i)461 for voteUserNumber in numbers:462 if "god" in hidden_vote_user['nickname'] and hidden_vote_content == voteUserNumber:463 hidden_votelists.clear()464 hidden_voteUserList.clear()465 for vote_user in hidden_vote_users:466 voteUser = vote_user['nickname']467 if voteUserNumber in voteUser:468 t.channel_message(f"شرÙع Ø±Ø£Û Ù
Ø®ÙÛ {voteUser}")469 t.change_status(0, f"شرÙع Ø±Ø£Û Ù
Ø®ÙÛ {voteUser}")470 hidden_voteUserList.add(voteUser)471 hidden_main_votelists.append(voteUser)472 hidden_vote.thread = threading.Timer(6, hidden_vote_end_message)473 hidden_vote.thread.daemon = True474 hidden_vote.thread.start()475 hidden_vote.thread_run = True476 @t.subscribe("messagedeliver")477 def hidden_vote_collection(server, params):478 if params["type"] != teamtalk.USER_MSG:479 return480 channel_user = t.get_user(params['srcuserid'])481 new_user = channel_user['nickname']482 if new_user:483 for vote_user_number in numbers:484 if vote_user_number in new_user:485 if not new_user in hidden_main_votelists:486 hidden_votelists.add(new_user)487 hidden_main_votelists.append(new_user)488 if "god" in hidden_vote_user['nickname'] and hidden_vote_content == "hv" or "god" in hidden_vote_user['nickname'] and hidden_vote_content == "ار":489 t.channel_message('\n'.join(hidden_vote_list_result))490 t.change_status(0, '\n'.join(hidden_vote_list_result))491 hidden_main_votelists.clear()492hidden_vote.thread = 'hv'493hidden_vote.thread_run = False494def card_selection():495 #با ÛÙ ØÙÙ٠تÙ
اÙ
کارتÙا را بصÙرت رÙدÙÙ
ب٠ÙÛست کارتÙØ§Û Ø¬Ø¯Ûد اضاÙÙ Ù
ÛÚ©ÙÛÙ
496 for i in range(0, len(card_name)):497 rand_card = random.choice(card_name)498 #Ø¨Ø±Ø§Û Ø¬ÙÙÚ¯ÛØ±Û Ø§Ø² تکرار کارت اÙتخاب شد٠تصادÙÛ Ø±Ù Ø§Ø² ÙÛست ØØ°Ù Ù
ÛÚ©ÙÛÙ
499 card_name.remove(rand_card)500 return rand_card501@t.subscribe("messagedeliver")502def card(server, params):503 if params["type"] != teamtalk.USER_MSG:504 return505 card_content = params["content"]506 card_user = t.get_user(params["srcuserid"])507 nickname = card_user["nickname"]508 if card_user.get('chanid') == int(chanid):509 if nickname == " god" and card_content == 'c' or nickname == " god" and card_content == 'ز':510 t.user_message(' god', 'Ø´Ù
ار٠کارت را داخ٠کاÙا٠Ùارد Ú©ÙÛد')511 @t.subscribe('messagedeliver')512 def Card_list(server, params):513 if params['type'] != teamtalk.USER_MSG:514 return515 card_list_content = params["content"]516 card_list_user = t.get_user(params["srcuserid"])517 nickname = card_list_user["nickname"]518 if card_list_user.get('chanid') == int(chanid):519 if nickname == " god" and card_list_content == "cl" or nickname == " god" and card_list_content == "زÙ
":520 t.channel_message(f"کارتÙØ§Û Ù
اÙد٠{' '.join(card_number)}")521 t.channel_message(f"ÙاÙ
کارتÙا {' '.join(card_name)}")522 @t.subscribe('messagedeliver')523 def Card_number(server, params):524 if params['type'] != teamtalk.CHANNEL_MSG:525 return526 card_number_content = params["content"]527 card_user = t.get_user(params["srcuserid"])528 nickname = card_user["nickname"]529 if card_user.get('chanid') == int(chanid):530 if len(card_number_content) == 1:531 for cardNumberList in card_number:532 if cardNumberList in card_number_content:533 if nickname == ' god':534 t.channel_message(f' کارت اÙتخاب شدÙ: {card_selection()}')535 card_number.remove(cardNumberList)536@t.subscribe("messagedeliver")537def help(server, params):538 if params["type"] != teamtalk.USER_MSG:539 return540 help_content = params["content"]541 help_user = t.get_user(params["srcuserid"])542 nickname = help_user["nickname"]543 if help_user.get('chanid') == int(chanid):544 if help_content == "help" or help_content == "راÙÙÙ
ا":545 t.user_message(help_user, 'ÙÙÛسÙدگا٠ربات: رÙÙا٠کÙ
اÙÛاÙ, ÙرÙاد Ù
ØÙ
دÛ, ÛÙدا ØسÙÙ¾Ùر, ØÙ
Ûد رضائÛ\nگاد Ø¨Ø§Ø²Û Ø¨Ø§Ûد اÙ٠اسÙ
Ø´ ÙاصÙ٠بزÙ٠٠بعد Ú©ÙÙ
Ù god ر٠بÙÙÛسÙ\nstart/شرÙع: شرÙع ÙÙشدÙÛ\nrl/ÙÙ
: ارسا٠ÙÙØ´Ùا ب٠گاد.\nf/ب: پاÛØ§Ù Ø¨Ø§Ø²Û Ù Ø±Ø§Ù Ø§ÙØ¯Ø§Ø²Û Ù
جدد ربات\nb/Ø°: ارسا٠broadcast در صÙرت Ùعا٠بÙØ¯Ù Ø¨Ø±Ø§Û id\nc/ز: شرÙع کارتÙØ§Û Ø¨Ø§Ø²Û\ncl/زÙ
: ارسا٠ÙÛست کارتÙا در کاÙاÙ\nv/ر Ø´Ù
ار٠بازÛÚ©Ù: شرÙع Ø±Ø£Û Ú¯ÛØ±Û Ù
عÙ
ÙÙÛ.')546 t.user_message(help_user, 'Ù
Ø®ÙÛ: شرÙع Ø±Ø£Û Ú¯ÛØ±Û Ù
Ø®ÙÛ.\nhv/ار: ارسا٠ÙتÛØ¬Ù Û Ø±Ø£Û Ú¯ÛØ±Û Ù
Ø®ÙÛ Ø¯Ø± کاÙاÙ.\nt/Ù Ø´Ù
ار٠بازÛÚ©Ù: شرÙع زÙ
ا٠صØبت Ù
عÙ
ÙÙÛ.\ntc/Ùز: Ùغ٠زÙ
ا٠صØبت Ù
عÙ
ÙÙÛ.\nch/زا Ø´Ù
ار٠بازÛÚ©Ù: شرÙع زÙ
ا٠ÚاÙØ´.\ncc/زز: Ùغ٠زÙ
ا٠ÚاÙØ´.\nd/Û Ø´Ù
ار٠بازÛÚ©Ù: شرÙع زÙ
ا٠دÙاع.\ndc/Ûز: Ùغ٠زÙ
ا٠دÙاع.\nhelp/راÙÙÙ
ا: راÙÙÙ
Ø§Û Ø±Ø¨Ø§Øª.')547def Login():548 global chanid549 if not os.path.exists('config.ini'):550 hostAddress = input('آدرس سÙرÙÙر را Ùارد Ú©ÙÛد.')551 tcpport = input('tcp Ù¾Ùرت سÙرÙÙر را Ùارد Ú©ÙÛد')552 channelID = input('id کاÙا٠را Ùارد ÙÙ
اÛÛد.')553 username = input('ÙاÙ
Ú©Ø§Ø±Ø¨Ø±Û Ø±Ø§ Ùارد Ú©ÙÛد')554 password = input('رÙ
ز عبÙر را Ùارد Ú©ÙÛد')555 nickname = input('اسÙ
Ù
ستعار Ûا nickname را Ùارد Ú©ÙÛد')556 client_name = input('ÙاÙ
سÙرÙÙر را Ùارد Ú©ÙÛد.')557 config_file = f"""558[options]559hostAddress = {hostAddress}560tcpport = {tcpport}561channel_id = {channelID}562username = {username}563password = {password}564nickname = {nickname}565clientName = {client_name}566"""567 file_creation = open('config.ini', 'x', encoding = 'utf-8-sig')568 file_creation .write(config_file)569 print('ÙاÛ٠کاÙÙÛÚ¯ با Ù
ÙÙÙÛت ساخت٠شد برÙاÙ
٠را با زد٠اÛÙتر بست٠٠Ù
جددا را٠اÙØ¯Ø§Ø²Û ÙÙ
اÛÛد.')570 input()571 else:572 try:573 config = configparser.ConfigParser()574 loaded = config.read('config.ini', encoding = 'utf-8-sig')575 host = config['options']['hostAddress']576 tcp = config['options']['tcpport']577 chanid = config['options']['channel_id']578 username = config['options']['username']579 password = config['options']['password']580 nickname = config['options']['nickname']581 clientName = config['options']['clientName']582 t.set_connection_info(host, tcp)583 t.connect()584 t.login(nickname, username, password, clientName)585 t.join(int(chanid))586 t.change_status(0, 'با ارسا٠کÙÙ
Ù help راÙÙÙ
Ø§Û Ø±Ø¨Ø§Øª ر٠Ù
ÛتÙÙÛد بخÙÙÛد.')587 print('برÙاÙ
٠در Øا٠اجرا Ù
Ûباشد.\r\nÙرÚÙ 2.0')588 try:589 t.handle_messages(timeout = 1)590 except teamtalk.TeamTalkError:591 if role_content == 'b' or role_content == 'Ø°':592 t.user_message(' god', 'اÙ
کا٠broadcast Ø¨Ø±Ø§Û Ø§ÛÙ id Ùعا٠ÙÛست pv ر٠ببÙد دÙبار٠باز Ú©Ù.')593 Login()594 else:595 t.user_message(' god', 'ببخش ک٠خطا Ù
ÛدÙ
باÛد برÙ
بÛاÙ
اÙ
ا ØاÙظÙ
پاک Ùشد٠ÙÙØ· باÛد pv ر٠ببÙØ¯Û Ø¯Ùبار٠باز بکÙÛ.')596 Login()597 except TypeError:598 t.user_message(' god', 'ببخش ک٠خطا Ù
ÛدÙ
باÛد برÙ
بÛاÙ
اÙ
ا ØاÙظÙ
پاک Ùشد٠ÙÙØ· باÛد pv ر٠ببÙØ¯Û Ø¯Ùبار٠باز بکÙÛ.')599 Login()600 except UnicodeDecodeError: 601 t.user_message(' god', 'ببخش ک٠خطا Ù
ÛدÙ
باÛد برÙ
بÛاÙ
اÙ
ا ØاÙظÙ
پاک Ùشد٠ÙÙØ· باÛد pv ر٠ببÙØ¯Û Ø¯Ùبار٠باز بکÙÛ.')602 Login()603 except KeyError:604 print('Ù
Ø´Ú©ÙÛ Ø¯Ø± ÙاÛ٠کاÙÙÛÚ¯ ÙجÙد دارد ÙاÛ٠کاÙÙÛÚ¯ را پاک کرد٠برÙاÙ
٠را Ù
جددا را٠اÙØ¯Ø§Ø²Û ÙÙ
اÛÛد.')605 input()...
qthread_signal_test.py
Source:qthread_signal_test.py
1'''Test cases for connecting signals between threads'''2import unittest3from PySide.QtCore import QThread, QObject, SIGNAL, QCoreApplication4thread_run = False5class Source(QObject):6 def __init__(self, *args):7 QObject.__init__(self, *args)8 def emit_sig(self):9 self.emit(SIGNAL('source()'))10class Target(QObject):11 def __init__(self, *args):12 QObject.__init__(self, *args)13 self.called = False14 def myslot(self):15 self.called = True16class ThreadJustConnects(QThread):17 def __init__(self, source, *args):18 QThread.__init__(self, *args)19 self.source = source20 self.target = Target()21 def run(self):22 global thread_run23 thread_run = True24 QObject.connect(self.source, SIGNAL('source()'), self.target.myslot)25 while not self.target.called:26 pass27class BasicConnection(unittest.TestCase):28 def testEmitOutsideThread(self):29 global thread_run30 app = QCoreApplication([])31 source = Source()32 thread = ThreadJustConnects(source)33 QObject.connect(thread, SIGNAL('finished()'), lambda: app.exit(0))34 thread.start()35 while not thread_run:36 pass37 source.emit_sig()38 app.exec_()39 thread.wait()40 self.assert_(thread.target.called)41if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!