示例#1
0
 async def maths_input(self, ctx, numbers, target):
     while True:
         m = await ctx.bot.wait_for(
             "message",
             check=lambda m: m.channel == ctx.channel and m.author != ctx.
             bot.user and m.content and all(
                 s in operators + numerals + ["x"] for s in m.content))
         player = get_user(m.author)
         content = m.content.replace("x", "*")
         if "//" in content:
             task(ctx.send("Floor division is not allowed!"))
             continue
         if "**" in content:
             task(ctx.send("Powers are not allowed!"))
             continue
         numbers_used = [
             int(n) for n in re.split(regexPattern, content) if n
         ]
         if not spellable(numbers_used, numbers):
             task(ctx.send("Incorrect numbers!"))
             continue
         try:
             result = eval(content)
             if result == target:
                 return player
             else:
                 task(ctx.send("Incorrect result: %s!" % result))
                 continue
         except Exception:
             task(
                 ctx.send(
                     "Something went wrong while executing your answer..."))
             continue
示例#2
0
 async def inv(self, ctx: commands.Context, other: discord.Member = None):
     target = economy.get_user(other or ctx.author)
     if target.inv:
         await ctx.send(f"{target.name}'s inventory:\n" +
                        "\n".join(f"{i.display_name}: {q}"
                                  for i, q in target.inv.items()))
     else:
         await ctx.send(f"{target.name} has no items...")
示例#3
0
 async def hangman(self, ctx):
     if ctx.channel in self.active:
         await ctx.send(
             "Wait for the current game in this channel to finish!")
         return
     player = get_user(ctx.author)
     if player.credits == 0:
         await ctx.send("You're broke and can't play hangman!")
         return
     self.active.append(ctx.channel)
     category = random.choice(list(wordlists.keys()))
     tword = random.choice(wordlists[category])
     cword = ["*"] * len(tword)
     guesses = []
     msg = None
     failed_horribly = False
     while True:
         s = "HANGMAN! Category: %s\n" % category + "".join(
             econv(c) for c in cword) + "\nWrong:" + "".join(
                 econv(c) for c in guesses if c not in cword)
         if msg:
             await msg.edit(content=s)
         else:
             msg = await ctx.send(s)
         if "*" not in cword:
             await ctx.send("Hooray! You got the word! +5c!")
             player.update_balance(5)
             break
         done, not_done = await asyncio.wait(
             [self.wait_for_input(ctx, player, guesses),
              asyncio.sleep(60)],
             return_when=asyncio.FIRST_COMPLETED)
         r = next(d for d in done).result()
         if r:
             l, to_delete = r
             for m in to_delete:
                 await asyncio.create_task(m.delete())
             guesses.append(l)
             if l in tword:
                 indices = [m.start() for m in re.finditer(l, tword)]
                 for i in indices:
                     cword[i] = l
             else:
                 player.update_balance(-1)
                 if player.credits == 0:
                     await ctx.send("You ran out of money! TOO BAD!")
                     failed_horribly = True
                     break
         else:
             await ctx.send(
                 "You spent too long thinking! TOO BAD! NO MONEY!")
             failed_horribly = True
             break
     if failed_horribly:
         await ctx.send("The word was %s" %
                        "".join(econv(l) for l in tword))
     self.active.remove(ctx.channel)
示例#4
0
文件: dib.py 项目: NoNotCar/CasinoBot
 async def join(self, ctx):
     self.refresh()
     if ctx.channel in self.games:
         u = get_user(ctx.author)
         u.nick=ctx.author.display_name
         success = await self.games[ctx.channel].join(ctx.author)
         await self.games[ctx.channel].pump()
         return success
     else:
         await ctx.send("No games currently in this channel...")
示例#5
0
文件: dib.py 项目: NoNotCar/CasinoBot
 async def shame(self,ctx):
     user = get_user(ctx.author)
     if ctx.channel in self.games:
         g = self.games[ctx.channel]
         if g.shameable:
             if shame:=g.ashamed:
                 msg = "%s, hurry the f**k up!" if user.has("f-word pass") else "%s, hurry up!"
                 tagging = user.remove_item("name tag")
                 await ctx.send(msg % smart_list([p.tag if tagging else p.name for p in shame]))
             else:
                 await ctx.send("Shame on you, nobody is busy!")
         else:
             await ctx.send("Unfortunately, shaming in this game would reveal too much information...")
示例#6
0
 async def flair(self, ctx: commands.Context, *, flair: str):
     user = economy.get_user(ctx.author)
     if flair.lower() == "none":
         user.flair = "%s"
         await ctx.send("Removed Flair!")
         economy.save()
         return
     if fitem := shopitems.get(flair):
         if isinstance(fitem, Flair):
             if user.inv[fitem]:
                 user.flair = fitem.flair
                 await ctx.send(f"Nice look, {user.name}!")
                 economy.save()
             else:
                 await ctx.send("BUY IT FIRST, YOU CHEAPSKATE!")
         else:
             await ctx.send("That's... not a flair.")
示例#7
0
文件: dib.py 项目: NoNotCar/CasinoBot
 async def join(self, author):
     if isinstance(author,discord.Member):
         user=get_user(author)
         if self.started:
             await self.send("The game has already started!")
             return False
         if any(p.user == user for p in self.players) and not TEST_PLAY_URSELF:
             await self.send("You're already playing!")
             return False
         elif not user.update_balance(-self.cost):
             await self.send("You don't have enough money to play!")
             return False
         else:
             self.players.append(self.playerclass(user))
             await self.send("%s has joined the game! Current players: %s" % (user.name, len(self.players)))
             return True
     else:
         self.players.append(author)
示例#8
0
 async def multibuy(self, ctx: commands.Context, quantity: int, *,
                    thing: str):
     buyer = economy.get_user(ctx.author)
     if quantity <= 0:
         await ctx.send(
             "You can't buy less than 1 of something, that's PREPOSTEROUS!")
         return
     if item := shopitems.get(thing):
         total_q = quantity + buyer.inv[item]
         if item.one and total_q > 1:
             await ctx.send("Sorry, you can't have more than one of that.")
             return
         total_cost = quantity * item.cost
         if buyer.update_balance(-total_cost):
             await ctx.send("Buying successful!")
             for _ in range(quantity):
                 await item.on_get(ctx.channel, buyer)
             economy.save()
示例#9
0
 async def pull(self,ctx,high_stakes=False):
     player=get_user(ctx.author)
     if not high_stakes and player==self.locked_out:
         m = await ctx.send("You're still locked out!")
         await asyncio.sleep(1)
         await m.delete()
         await ctx.message.delete()
         return
     cost=20 if high_stakes else 2
     if self.using:
         m=await ctx.send("Wait for the current player to finish!")
         await asyncio.sleep(1)
         await m.delete()
         await ctx.message.delete()
         return
     if high_stakes and not random.randint(0,9):
         for n in range(4):
             await ctx.send("PULL" if n%2 else "SUPER")
             await asyncio.sleep(1)
     if player.update_balance(-cost):
         self.using=True
         await ctx.send("You put a %s in the machine..." % ("20c note" if high_stakes else "2c coin"))
         slots=await ctx.send(":question:"*3)
         result=[]
         for n in range(3):
             await asyncio.sleep(1)
             result.append(random.choice(self.high_stakes_wheel if high_stakes else self.wheel)())
             await slots.edit(content="".join(s.emoji for s in result)+":question:"*(2-n))
         self.using=False
         if all(r==result[0] for r in result):
             await result[0].on_triple(ctx,player)
         else:
             winnings=sum(s.value for s in result)
             if winnings<=0:
                 if len([s for s in result if isinstance(s,Skull)])==2:
                     await ctx.send("DOUBLE SKULL: You're locked out of playing the normal stakes machine until someone else gets this...")
                     self.locked_out=player
                 else:
                     await ctx.send("Too bad, you didn't win anything")
             else:
                 await ctx.send("You won %sc!" % winnings)
                 player.update_balance(winnings)
     else:
         await ctx.send("You need %s credits to use this slot machine!" % cost)
示例#10
0
 async def maths(self, ctx, difficulty="medium"):
     try:
         target = {
             "easy": 0.1,
             "medium": 0.5,
             "hard": 0.9,
             "extreme": 1.0,
             "mathmo": 1.0
         }[difficulty]
     except KeyError:
         await ctx.send("not a valid difficulty!")
         return
     if not get_user(ctx.author).update_balance(-1):
         await ctx.send("You're _too poor_ for countdown!")
         return
     numbers = random.choices(list(range(1, 10)), k=4) + random.choices(
         [10, 25, 50, 75, 100], k=2)
     results = {
         k: v
         for k, v in recursive_maths(numbers).items()
         if (1000 <= k < 9999 if difficulty == "mathmo" else 100 <= k < 999)
     }
     results = sorted(((k, v) for k, v in results.items()),
                      key=lambda p: p[1],
                      reverse=True)
     results = [r[0] for r in results]
     target = results[int(min(len(results) * target, len(results) - 1))]
     done, not_done = await asyncio.wait(
         [
             self.manage_countdown(
                 ctx, numbers, self.time[difficulty], target=target),
             self.maths_input(ctx, numbers, target)
         ],
         return_when=asyncio.FIRST_COMPLETED)
     winner = next(d for d in done).result()
     next(d for d in not_done).cancel()
     if winner:
         winnings = self.winnings[difficulty]
         await ctx.send("Well done %s! You won %sc!" %
                        (winner.nick, winnings))
         winner.update_balance(winnings)
     else:
         await ctx.send("Nobody won...")
示例#11
0
文件: dib.py 项目: NoNotCar/CasinoBot
 async def start(self,ctx, game:str):
     self.refresh()
     game = game.lower()
     if ctx.channel in self.games:
         await ctx.send("There's already a game of %s in this channel" % self.games[ctx.channel].name)
     else:
         u = get_user(ctx.author)
         u.nick=ctx.author.display_name
         if game in self.game_classes:
             g = self.game_classes[game](ctx)
             self.games[ctx.channel] = g
             if g.all_play:
                 g.players = [g.playerclass(u) for u in economy.users.values() if not isinstance(u,economy.BankUser)]
                 await self.begin(ctx)
                 return g
             if await g.join(ctx.author):
                 await g.pump()
                 return g
             await g.pump()
         else:
             await ctx.send("Game not found: %s" % game)
示例#12
0
 async def user_input(self, ctx, letters, udict):
     done = set()
     while True:
         m = await ctx.bot.wait_for(
             "message",
             check=lambda m: m.channel == ctx.channel and m.author != ctx.
             bot.user and m.content and " " not in m.content and "?" not in
             m.content)
         player = get_user(m.author)
         content = m.content.lower()
         if content in done:
             task(ctx.send("Someone's already got that word!"))
             continue
         if player in udict and len(udict[player]) >= len(content):
             task(
                 ctx.send(
                     "You've got a word of equal or greater length already!"
                 ))
             continue
         if spellable(content, letters):
             if content in words:
                 mx = (max(len(w) for w in udict.values()) if udict else 0)
                 if len(content) > mx:
                     task(
                         ctx.send("%s has the new longest word!" %
                                  player.nick))
                 elif len(content) == mx:
                     task(
                         ctx.send("%s has equalled the longest word!" %
                                  player.nick))
                 else:
                     task(
                         ctx.send("%s has got a word of length %s" %
                                  (player.nick, len(content))))
                 udict[player] = content
                 done.add(content)
             else:
                 task(ctx.send("That word is not in the dictionary!"))
         else:
             task(ctx.send("not spellable using these letters..."))
示例#13
0
 async def play(self, ctx, conundrum=None, wild=False):
     cost = 5 if conundrum else 2 if wild else 1
     if ctx.channel in self.games:
         await ctx.send("Game already running in this channel!")
         return
     if not get_user(ctx.author).update_balance(-cost):
         await ctx.send("You're _too poor_ for countdown!")
         return
     self.games.append(ctx.channel)
     letters = list(
         conundrum if conundrum else random.sample(word_list.ldist, 9))
     random.shuffle(letters)
     if wild:
         letters[8] = "*"
     udict = {}
     longest_word = conundrum if conundrum else next(
         w for w in searchlist if spellable(w, letters))
     t1, ui = await asyncio.wait([
         self.manage_countdown(ctx, letters, 30),
         self.user_input(ctx, letters, udict)
     ],
                                 return_when=asyncio.FIRST_COMPLETED)
     for u in ui:
         u.cancel()
     s = "Game finished! Longest word possible: %s" % longest_word
     win_word = max(len(w) for w in udict.values()) if udict else None
     winners = [u for u, w in udict.items() if len(w) == win_word]
     for u, w in udict.items():
         winnings = 20 if len(w) == 9 else 8 if len(w) == 8 else 5 if len(
             w) == len(longest_word
                       ) else 2 if len(w) == len(longest_word) - 1 else 0
         if u in winners and len(udict) > 1:
             winnings += 2
         s += "\n%s %s a word of length %s. They get %sc" % (
             u.nick, "won with" if u in winners else "got", len(w),
             winnings)
         u.update_balance(winnings)
     await ctx.send(s)
     self.games.remove(ctx.channel)
示例#14
0
async def wait_for_tag(ctx,player):
    m = await ctx.bot.wait_for("message",check=lambda m: m.author == player.user and len(m.mentions) == 1 and m.mentions[0]!=player.user)
    return get_user(m.mentions[0])