async def show(self, bot, dice, shooter_id, table, first_roll, display_channel): # set pace based on test mode self.timeout = 6.0 self.roll_duration = 0.0 self.nap = 0.4 self.leave_dice_for = 2.0 if bot.TEST_MODE or table.empty: self.timeout = 2.0 self.roll_duration = 0.0 self.nap = 0.1 self.leave_dice_for = 1.0 if shooter_id: user = await bot.fetch_user(shooter_id) bets_in = T.bold("Bets are IN!") wait_str = T.block_quote(f"Waiting {self.timeout:.0f} seconds for " f"{user.display_name} to `roll`...") waiting = await display_channel.send(f'{bets_in}\n{wait_str}') else: await display_channel.send(f'No shooter. Auto-rolling...') return await self.roll(dice, display_channel) def check(m): if m.author.id != shooter_id: return False return True if self.__class__.get_roll_command(m) else False try: resp = await bot.wait_for('message', check=check, timeout=self.timeout) roll_cmd = self.__class__.get_roll_command(resp) if not roll_cmd: raise SceneException( f"Unexpected roll command: {resp.content}") # add some extra flavor if the shooter blew on the dice if roll_cmd == self.__class__.BLOW_CMDS[0]: await resp.add_reaction(E.BLOW) await resp.add_reaction(E.DIE) # full banter only happens when the player initiates the roll. banter = self.banter(table.point, True) await display_channel.send(banter) except asyncio.TimeoutError: async with display_channel.typing(): await waiting.add_reaction(E.HOURGLASS) await asyncio.sleep(self.nap) new_content = waiting.content + " nevermind, I can do it for you." await waiting.edit(content=new_content) await asyncio.sleep(self.nap) banter = self.banter(table.point, False) await display_channel.send(banter) finally: await asyncio.sleep(3 * self.nap) return await self.roll(dice, display_channel)
def make_table(self, table, allowed_bets, time_remaining): ascii_table = AsciiTable.from_table(table) place_bets = T.bold("Place your bets!") place_bets += f" You have {time_remaining:.0f} " if time_remaining < self.timeout: place_bets += "more seconds to bet..." else: place_bets += "seconds." valid_bets = ", ".join([T.inline_mono(b) for b in allowed_bets]) valid_bets = T.block_quote("Valid bets are: " + valid_bets) return (f'{ascii_table}\n' f'{place_bets}\n' f'{valid_bets}\n')
def getScreen(stdscr): return Screen(stdscr, 8, 4, [Text(1, 2, 'Register')], [[TextInput(2, 2, "Name")], [TextInput(3, 2, "ShortDsc")], [TextInput(4, 2, "Desc")], [TextInput(5, 2, "Value")], [TextInput(6, 2, "Category")], [AddButton(7, 1, "Add"), BackButton(7, 3, "Back")]])
def show_dice(cls, dice): d1 = cls.dice[dice.values[0]] d2 = cls.dice[dice.values[1]] s = "" for d1_row, d2_row in zip(d1, d2): s += f' {d1_row} {d2_row}\n' return T.mono(s)
def getScreen(stdscr): return Screen( stdscr, 8, 4, [Text(1, 2, 'Register')], [[TextInput(2, 2, "Username")], [TextInput(3, 2, "Password")], [TextInput(4, 2, "First")], [TextInput(5, 2, "Last")], [TextInput(6, 2, "Role")], [RegisterButton(7, 1, "Register"), BackButton(7, 3, "Back")]])
async def leave(self, member: Member, channel: TextChannel): table, delegate = await self.allowed_channel(channel) player = table.player_for(member.id) if not player: return await channel.send(f'{member.name} not seated at a table!') unseated = table.unseat(player.id) summary = T.mono(' ' + str(unseated)) await channel.send(f'{member.name} left table\n{summary}')
async def notify_cleared_players( self, cleared ): cleared_str = T.mono("\n".join([str(p) for p in cleared])) await self.display_channel.send( f'Clearing players due to inactivity. Place ' f'a bet at any time to rejoin. Cleared: \n{cleared_str}' ) await asyncio.sleep(1.5)
async def report_exception( self, exception: Exception ): exception_str = T.block_quote( f'{T.inline_mono(type(exception))}\n{str(exception)}') await self.display_channel.send( f'Sorry to show you this, but could you let Andy know he has an ' f'unhandled exception:\n{exception_str}', )
def __init__(self, screen: pygame.Surface, score: int): self.running = True self.bg = (0, 130, 0) self.screen_w = screen.get_width() self.screen_h = screen.get_height() # Buttons self.btn_w = 120 self.btn_h = 50 self.btn_ds_x = (self.screen_w - self.btn_w) // 3.3 self.btn_s_x = (self.screen_w - self.btn_w) // 1.4 self.btn_y = (self.screen_h - self.btn_h) // 2 self.btn_dont_save = Button(self.btn_ds_x, self.btn_y, self.btn_w, self.btn_h, (200, 0, 0), (255, 0, 0), "Don't Save", self.close_hiscore) self.btn_save = Button(self.btn_s_x, self.btn_y, self.btn_w, self.btn_h, (0, 0, 200), (0, 0, 255), 'Save', self.close_hiscore) self.buttons = (self.btn_dont_save, self.btn_save) # Input Field self.field_w = 150 self.field_h = 50 self.field_x = (self.screen_w - self.field_w) // 2 self.field_y = (self.screen_h - self.field_h) // 3 self.initials_field = Input_Field(self.field_x, self.field_y, self.field_w, self.field_h, (255, 255, 255), (200, 200, 200)) # Score Text self.score = score self.score_text = Text(self.screen_w // 3, self.screen_h // 1.7, 22, f'Your score is {self.score}!') # Initials Text self.initials_text = Text(self.screen_w // 5, self.screen_h // 4.2, 18, 'Enter your initials to save your score') self.drawables = (self.btn_dont_save, self.btn_save, self.initials_field, self.score_text, self.initials_text)
async def me(self, member: Member, channel: TextChannel): table, delegate = await self.allowed_channel(channel) player = table.player_for(member.id) if not player: return await channel.send(f'{member.name} not seated at a table!') s = f"{str(player)}" if player.active_bets: for ab in player.active_bets: s += "\n " + str(ab) else: s += "\n " + "NO ACTIVE BETS" await channel.send(T.mono(s))
def find_unique_tele_numbers(texts, calls): uniq_tele_nums = set({}) # using set instead of dict for call in calls: call = Call(call) uniq_tele_nums.add(call.incoming) uniq_tele_nums.add(call.answering) for text in texts: text = Text(text) uniq_tele_nums.add(text.incoming) uniq_tele_nums.add(text.answering) return len(uniq_tele_nums)
def getScreen(stdscr): sess = utils.getSession() inps = [ SearchButton(2, 1, "Search"), AddButton(2, 2, "Add"), BackButton(2, 3, "Back") ] if sess['role'] == 'employees' or sess['role'] == 'managers' else [ SearchButton(2, 1, "Search"), BackButton(2, 3, "Back") ] return Screen( stdscr, 3, 4, [Text(1, 2, 'Would you like to add or search for donations?')], [inps])
async def show_leaderboard(self, guild, channel): if not guild: return table, delegate = await self.allowed_channel(channel) if not table: return players = table.all_players players.sort(key=lambda p: p.net_worth, reverse=True) players = players[:20] title = T.bold(f"{E.TROPHY} {guild.name} Top Earners {E.TROPHY}") player_str = "\n".join( [f"{i + 1:2.0f} - " + str(p) for i, p in enumerate(players)]) leaderboard = await channel.send(f'{title}{T.mono(player_str)}') await leaderboard.add_reaction(E.TROPHY)
def find_telemarkers(calls, texts): outgoing = set({}) non_tele = set({}) for call in calls: call = Call(call) outgoing.add(call.incoming) non_tele.add(call.answering) for text in texts: text = Text(text) non_tele.add(text.incoming) non_tele.add(text.answering) possible_tele = list(outgoing - non_tele) possible_tele.sort() return possible_tele
def getScreen(stdscr, location): loc = { 'name': 0, 'type': 1, 'latitude': 2, 'longitude': 3, 'address': 4, 'phone': 5 } txts = [ Text(loc[k] + 1, 1, ((k.upper() + ': ').ljust(15)) + str(location[k]).ljust(50)) for k in location.keys() if k in loc ] return Screen(stdscr, 8, 2, txts, [[BackButton(7, 1, "Back")]])
async def show( self, bot, payouts, table, dice, outcome, channel ): by_player = {} payouts_exist = False for p in payouts: if p.player_id not in by_player: by_player[p.player_id] = [] by_player[p.player_id].append(p) s = "" for seat in table.seats: if seat.empty: continue player = seat.player payouts = by_player.get(player.id) if not payouts: continue s += f' \n\n{player}\n ' s += '\n '.join([str(po) for po in payouts]) payouts_exist = True if s: s = T.mono("PAYOUTS / LOSSES" + s) outcome = T.bold(f"ROLLED {dice.total}: ") + outcome.value await channel.send(outcome + s) sleep = 4.0 if bot.TEST_MODE: sleep = 1.0 if payouts_exist: await channel.trigger_typing() await asyncio.sleep(sleep)
def getScreen(stdscr): r = requests.get(API_URL + '/locations') js = r.json() rows = len(js['locations']) + 4 locations = [[LocationButton(i + 2, 2, js['locations'][i]['name'], js['locations'][i])] for i in range(len(js['locations']))] locations += [[DonationsButton(rows - 1, 1, "Donations"), MapButton(rows - 1, 2, "Map"), BackButton(rows - 1, 3, "Back")]] sess = utils.getSession() return Screen( stdscr, rows, 4, [ Text(1, 2, 'Welcome %s %s you are a %s.' % (sess['firstname'], sess['lastname'], sess['role'][:len(sess['role']) - 1])) ], locations )
def getScreen(stdscr, donation): don = { 'name': 0, 'locationid': 1, 'tstamp': 2, 'shortdescription': 3, 'description': 4, 'comments': 5, 'value': 6, 'category': 7 } txts = [ Text(don[k] + 1, 1, ((k.upper() + ': ').ljust(20)) + str(donation[k]).ljust(50)) for k in donation.keys() if k in don ] return Screen(stdscr, 10, 2, txts, [[BackButton(9, 1, "Back")]])
async def show( self, bot, roll_outcome, table, payouts, dice, next_shooter_id, channel ): sleep = 0.5 if not bot.TEST_MODE else 0.1 s = T.bold('Turns over! Next shooter\'s turn!') m = await channel.send(s) await m.add_reaction(E.SEVEN) await asyncio.sleep(sleep) await m.add_reaction(E.MONEY_WINGS) await asyncio.sleep(sleep) await m.add_reaction(E.SAD) await channel.trigger_typing() await asyncio.sleep(8 * sleep)
def empty(cls): return T.mono('\n'.join(cls.table))
async def show(self, bot, table, allowed_bet_types, display_channel, dealer): if bot.TEST_MODE: self.timeout = 2.5 else: if table.empty: self.timeout = 5.0 allowed_bets = [bt.cmd_name for bt in allowed_bet_types] if not allowed_bets: no_bets = T.block_quote("No allowed bets right now!") ascii_table = AsciiTable.from_table(table) await display_channel.send(f'{ascii_table}\n' f'{no_bets}\n') return [] def check(m): tokens = m.content.lower().strip().split() bet_type = tokens[0] if bet_type == 'roll': if m.channel == display_channel: msg = random.choice(self.wait_messages) asyncio.get_event_loop().create_task(m.reply(msg)) if bet_type not in allowed_bets: return False try: amount = tokens[1] float(amount) return True except Exception: return False return False bet_msg = await display_channel.send( self.make_table(table, allowed_bets, self.timeout)) timeout = self.timeout start = dt.utcnow() while True: try: left = timeout - (dt.utcnow() - start).total_seconds() left = max(left, self.time_increase_per_bet) left = min(left, self.timeout) if left < 0.0: raise asyncio.TimeoutError() m = await bot.wait_for('message', check=check, timeout=left) tokens = m.content.lower().strip().split() bet_type = tokens[0] amount = float(tokens[1]) u_id = m.author.id bet = None for bt in allowed_bet_types: if bt.cmd_name == bet_type: bet = bt.bet_class(amount, u_id) break if not bet: raise ValueError("No bet class found") player = table.player_for(u_id) if not player: player = table.create_player(u_id, m.author.display_name) try: table.sit(player.id) except AlreadyExists: pass left = timeout - (dt.utcnow() - start).total_seconds() left = max(left, self.time_increase_per_bet) left = min(left, self.timeout) await self.handle_bet(bet, m, player, dealer, bet_msg, table, allowed_bets, left) except asyncio.TimeoutError: await bet_msg.add_reaction(E.HOURGLASS) break return self.new_bets
def from_table(cls, table, include_players=True): ascii_table = AsciiTable.empty() btn_idx = table.button_position + 1 if not table.empty: b_idx = ascii_table.find(str(btn_idx)) if btn_idx in cls.left_seats: b_idx += 1 else: b_idx -= 1 else: # dealer gets button b_idx = ascii_table.find('●') b_idx += 1 # let's use the 3 die for now button = cls.little_dice[2] ascii_table = (f'{ascii_table[:b_idx]}' f'{button}' f'{ascii_table[b_idx + 1:]}') player_str = "" empty_seats = [] for s in table.seats: i = s.index + 1 p = ' ' if s.occupied: p = f'{i:.0f}' # add chips to pass line if s.player.has_pass_bet: p_idx = ascii_table.find(p) if i in cls.left_seats: chip_idx = p_idx + 3 else: chip_idx = p_idx - 3 ascii_table = (f'{ascii_table[:chip_idx]}' f'{cls.CHIP}' f'{ascii_table[chip_idx + 1:]}') # add chips to don't pass line if s.player.has_no_pass_bet: p_idx = ascii_table.find(p) if i in cls.left_seats: chip_idx = p_idx + 5 else: chip_idx = p_idx - 5 ascii_table = (f'{ascii_table[:chip_idx]}' f'{cls.CHIP}' f'{ascii_table[chip_idx + 1:]}') coin_str = f'[${s.player.coins:.0f}' coin_str += f'|${s.player.coins_on_table:.0f}]' player_str += (f'\n {p} - {str(s.player)}') else: empty_seats.append(i) # replace the integers in the template string either # with an empty space OR with the same number ascii_table = ascii_table.replace(str(i), p) if table.point: ascii_table = ascii_table.replace("OFF", f'{table.point:2.0f} ') seats_str = "\nSEATS" if empty_seats: seats_str += f' ({len(empty_seats)} empty) - place bet to sit\n' else: seats_str += f' (table is full)\n' if include_players: ascii_table += T.bold(seats_str) if player_str: ascii_table += f'{T.mono(player_str)}' return ascii_table
def getScreen(stdscr): return Screen( stdscr, 5, 4, [Text(1, 2, 'Search')], [[TextInput(2, 2, "Category")], [TextInput(3, 2, "Name")], [SearchResultsButton(4, 1, "Search"), BackButton(4, 3, "Back")]])
def getScreen(stdscr): return Screen( stdscr, 5, 4, [Text(1, 2, 'Login')], [[TextInput(2, 2, "Username")], [TextInput(3, 2, "Password")], [LoginButton(4, 1, "Login"), BackButton(4, 3, "Back")]])
def getScreen(stdscr): return Screen( stdscr, 3, 4, [Text(1, 2, 'Welcome to Donation Tracker')], [[LoginButton(2, 1, "Login"), RegisterButton(2, 3, "Register")]])
def __init__(self): # Liste des modules self.modules = OrderedDict({ "header": { "active": True, "filter": False, "exec": self.module_header }, "text": { "active": False, "filter": False, "exec": self.module_text }, "mdldyna": { "active": False, "filter": False, "exec": self.module_mdldyna }, "mdlobj": { "active": False, "filter": False, "exec": self.module_mdlobj }, "item": { "active": False, "filter": False, "exec": self.module_item }, "mover": { "active": False, "filter": False, "exec": self.module_mover }, "world": { "active": True, "filter": False, "exec": self.module_world }, "quest": { "active": False, "filter": False, "exec": self.module_quest }, "drop": { "active": False, "filter": False, "exec": self.module_quest }, "ai": { "active": False, "filter": False, "exec": self.module_ai }, "event_monster": { "active": False, "filter": False, "exec": self.module_event_monster }, "skill": { "active": False, "filter": False, "exec": self.module_skill }, "ctrl": { "active": False, "filter": False, "exec": self.module_ctrl }, "karma": { "active": False, "filter": False, "exec": self.module_karma }, "diepenalty": { "active": False, "filter": False, "exec": self.module_die_penalty }, "filter": { "active": False, "filter": False, "exec": None }, "invalid": { "active": False, "filter": False, "exec": self.module_invalid }, "letter": { "active": False, "filter": False, "exec": self.module_letter } }) # Liste des textes chargé self.texts = OrderedDict({ "ctrl": Text(), "item": Text(), "karma": Text(), "mover": Text(), "skill": Text(), "troupeskill": Text(), "dubear": Text(), "dudadk": Text(), "dudreadfulcave": Text(), "duflmas": Text(), "dukrr": Text(), "dumuscle": Text(), "duominous": Text(), "duominous_1": Text(), "durustia": Text(), "durustia_1": Text(), "dusatemple": Text(), "dusatempleboss": Text(), "wdarena": Text(), "wdguildhouselarge": Text(), "wdguildhousemiddle": Text(), "wdguildhousesmall": Text(), "wdguildwar": Text(), "wdguildwar1to1": Text(), "wdheaven01": Text(), "wdheaven02": Text(), "wdheaven03": Text(), "wdheaven04": Text(), "wdheaven05": Text(), "wdheaven06": Text(), "wdheaven06_1": Text(), "wdkebaras": Text(), "wdmadrigal": Text(), "wdminiroom": Text(), "wdquiz": Text(), "wdvolcane": Text(), "wdvolcanered": Text(), "wdvolcaneyellow": Text(), "faq": Text(), "gameguard": Text(), "guide": Text(), "help": Text(), "instanthelp": Text(), "minigame_alphabet": Text(), "patchclient": Text(), "tip": Text(), "treehelp": Text(), "tutorial": Text(), "character_etc": Text(), "character_school": Text(), "character": Text(), "etc": Text(), "honorlist": Text(), "lordskill": Text(), "patroldestination": Text(), "propitemetc": Text(), "propmotion": Text(), "propquest_dungeonandpk": Text(), "propquest_requestbox": Text(), "propquest_requestbox2": Text(), "propquest_scenario": Text(), "propquest": Text(), "questdestination": Text(), "resdata": Text(), "textclient": Text(), "textemotion": Text(), "dubear": Text(), "dudadk": Text(), "dudreadfulcave": Text(), "duflmas": Text(), "dukrr": Text(), "dumuscle": Text(), "duominous": Text(), "duominous_1": Text(), "durustia": Text(), "durustia_1": Text(), "dusatempleboss": Text(), "wdarena": Text(), "wdguildhouselarge": Text(), "wdguildhousemiddle": Text(), "wdguildhousesmall": Text(), "wdguildwar": Text(), "wdheaven01": Text(), "wdheaven02": Text(), "wdheaven03": Text(), "wdheaven04": Text(), "wdheaven05": Text(), "wdheaven06": Text(), "wdheaven06_1": Text(), "wdkebaras": Text(), "wdmadrigal": Text(), "wdminiroom": Text(), "wdquiz": Text(), "wdvolcane": Text(), "wdvolcanered": Text(), "wdvolcaneyellow": Text(), "world": Text() }) # Liste des defines self.defines = OrderedDict({ "define": Define(), "attribute": Define(), "item": Define(), "item_kind": Define(), "job": Define(), "neuz": Define(), "obj": Define(), "skill": Define(), "sound": Define(), "world": Define(), "continent": Define(), "event": Define(), "lord_skill": Define(), "quest": Define(), "honor": Define(), "lang": Define(), "msghdr": Define(), "resdata": Define(), "wnd_style": Define(), }) # Instance des object et mondes self.mdl_dyna = MdlDyna() self.mdl_obj = MdlObj() self.worlds_manager= WorldManager() # Instance des classes Propriétés self.prop_item = PropItem() self.prop_mover = PropMover() self.prop_mover_ex = PropMoverEx() self.prop_ai = PropMoverExAI() self.prop_ctrl = PropCtrl() self.prop_skill = PropSkill() self.prop_troupe_skill = PropTroupeSkill() self.prop_karma = PropKarma() self.prop_quest = PropQuest() # Instance des classes utiles self.filter = Filter() self.letter = Letter() self.invalid = Invalid() # Instance des classes events self.die_penalty = DiePenalty() self.random_event_monster = RandomEventMonster()
def __init__(self, option_delegate: EmbedOptionDelegate): super().__init__(T.bold("What's the haps?!"), "We're playing craps!", option_delegate=option_delegate) options = self.create_options() self.add_options(options)