Exemple #1
0
 async def crank(self, ctx):  # Should cost about 5 points.
     """Cranks a slot machine. Costs 5 points to play.\nThis command takes no input."""
     currP = fetch_data('points_register', ctx.message.author.id)
     if currP is None:
         await ctx.send('Can\'t find you in the register, sorry!')
         return
     if currP < 5:
         await ctx.send('You can\'t afford that silly!')
         return
     outcome = [getSlot(), getSlot(), getSlot()]
     outcome = list(zip(*outcome[::-1]))
     win = 0
     for i in range(3):
         if len(set(outcome[i])) == 1:
             win += weights[outcome[i][0]]
     if outcome[0][0] == outcome[1][1] and outcome[1][1] == outcome[2][2]:
         win += weights[outcome[1][1]]
     if outcome[0][2] == outcome[1][1] and outcome[1][1] == outcome[2][0]:
         win += weights[outcome[1][1]]
     outcome = [' '.join(k) for k in outcome]
     outcome = '\n'.join(outcome)
     await ctx.send(outcome)
     if win > 0:
         if not write_data('points_register', ctx.message.author.id, currP + win - 5):
             await ctx.send('Point registration failed.')
             return
         await ctx.send('Congratiulations, you win ' + str(win) + ' points!')
     else:
         if not write_data('points_register', ctx.message.author.id, currP - 5):
             await ctx.send('Point registration failed.')
             return
         await ctx.send('No points for you, sorry!')
Exemple #2
0
 async def claimpoints(self, ctx):
     """Lets a user claim 10 points per day.\nThis command takes no input."""
     tmp = '{0.mention}'.format(ctx.message.author)
     now = datetime.date.today()
     lastStr = fetch_data('last_claimed', ctx.message.author.id)
     oldPoints = fetch_data('points_register', ctx.message.author.id)
     if oldPoints is None:
         await ctx.send('Coudln\'t find ' + tmp + ' in the register!')
         return
     if lastStr is None:
         if not write_data('last_claimed', ctx.message.author.id, str(now)):
             await ctx.send('Time data reading/writing failed, sorry!')
             return
         dt = 1
     else:
         lastArg = list(map(int, lastStr.split('-')))
         lastT = datetime.date(lastArg[0], lastArg[1], lastArg[2])
         if not write_data('last_claimed', ctx.message.author.id, str(now)):
             await ctx.send('Time data reading/writing failed, sorry!')
             return
         dt = (now - lastT).days
     dt = max(0, dt)
     dt = min(5, dt)
     if dt == 0:
         await ctx.send('You already claimed your points today ' + tmp + '!')
         return
     if not write_data('points_register', ctx.message.author.id, oldPoints + 10 * dt):
         await ctx.send('Point data reading/wrinting failed, sorry!')
         return
     await ctx.send('Enjoy your ' + str(10 * dt) + ' points ' + tmp + '!')
Exemple #3
0
 async def setbonus(self, ctx):
     """
     Sets a player's initiative bonus. Takes input in the format ?setbonus n. 
     The command can also be called as ?setbonus custom [rollstr] where rollstr is a valid string of dice rolls. 
     Thus ?setbonus 1 and ?setbonus custom 1d20 + 1 do the same thing.
     Furthermore, in a custom string, several rolls can be separated by semicolons.
     So if characters act on more than one initiative, perhaps one with bonus 1 and another with initiative 1d16 + 2 the command would be
     ?setbonus custom 1d20 + 1; 1d16 + 2
     """
     param = ctx.message.content.split(None, 1)[1]
     rollstr = ""
     try:
         n = int(param)
         if n > 0:
             rollstr = "1d20+" + str(n)
         elif n < 0:
             rollstr = "1d20-" + str(abs(n))
         else:
             rollstr = "1d20"
     except ValueError:
         param = param.split(None, 1)
         if param[0] != "custom":
             await ctx.send('Your input is invalid!')
             return
         rollstr = param[1]
     name = fetch_data('initiative_names', str(ctx.message.author.id))
     if not name:
         await ctx.send('No name registered yet!')
         return
     if not write_data('initiative_register', name, rollstr):
         await ctx.send('Initiative registration failed.')
         return
     await ctx.send('Initiative registered!')
Exemple #4
0
 async def saveroll(self, ctx):
     """Saves a roll string for later use. ?saveroll name [dicestr]."""
     s = ctx.message.content.split(None, 1)[1]
     name, dice = s.split(None, 1)
     if not write_data('saved_rolls', (ctx.message.author.id, name), dice):
         await ctx.send('File IO failed!')
         return
     await ctx.send('Roll saved!')
Exemple #5
0
 async def setname(self, ctx):
     """Sets the user's name in initiative tables."""
     param = ctx.message.content.split(None, 1)[1]
     param.strip()
     if not write_data('initiative_names', ctx.message.author.id, param):
         await ctx.send('Name registration failed.')
         return
     await ctx.send('Name registered!')
Exemple #6
0
 async def newpointentry(self, ctx):
     """Creates an entry for a user in the points register so they can use the other point-related commands.\nThis command takes no input."""
     tmp = '{0.mention}'.format(ctx.message.author)
     if fetch_data('points_register', ctx.message.author.id) is not None:
         await ctx.send(tmp + 'is already in the register!')
     elif write_data('points_register', ctx.message.author.id, 0):
         await ctx.send(tmp + ' has been added to the points register!')
     else:
         await ctx.send('Data writing failed.')
Exemple #7
0
 async def setinitiative(self, ctx):
     """Sets initiative for a name. Called as ?setinitiative [name] [value]."""
     _, name, val = ctx.message.content.split()
     try:
         val = int(val)
     except ValueError:
         await ctx.send('That is not a valid initiative!')
         return
     if not write_data('initiative_table', name, val):
         await ctx.send('Initiative registration failed.')
         return
     await ctx.send('Initiative registered!')
Exemple #8
0
 async def bet(self, ctx):
     """Lets a user bet points in hopes of getting more. This is almost a zero-sum game, it only rounds down to the nearest whole number away from a zero-sum game.\nTakes input in the form ?bet points_to_bet odds_to_win:odds_to_lose."""
     currPoints = fetch_data('points_register', ctx.message.author.id)
     if currPoints is None:
         await ctx.send('Point data reading/writing failed, sorry!')
         return
     tmp = '{0.mention}'.format(ctx.message.author)
     try:
         wager = int(ctx.message.content.split()[1])
         o1, o2 = map(int, ctx.message.content.split()[2].split(':'))
     except Exception:
         await ctx.send('Give the input in an orderly format silly!')
         return
     if wager <= 0 or o1 <= 0 or o2 <= 0:
         await ctx.send('Give the input in an orderly format silly!')
         return
     if wager > currPoints:
         await ctx.send('You don\'t have that many points!')
         return
     if o1 > 1000 or o2 > 1000:
         await ctx.send('I\'m not ready to take a bet that big!')
         return
     res = random.randint(1, o1 + o2)
     if res <= o1:
         gain = o2 * wager // o1
         if not write_data('points_register', ctx.message.author.id, currPoints + gain):
             await ctx.send('Point data reading/writing failed, sorry!')
             return
         if gain == 1:
             await ctx.send('Yay! You win 1 point!')
         else:
             await ctx.send('Yay! You win ' + str(gain) + ' points!')
     else:
         if not write_data('points_register', ctx.message.author.id, currPoints - wager):
             await ctx.send('Point data reading/writing failed, sorry!')
             return
         if wager == 1:
             await ctx.send('Oh no! You lost 1 point!')
         else:
             await ctx.send('Oh no! You lost ' + str(wager) + ' points!')	
Exemple #9
0
 async def rollinitiatives(self, ctx):
     """Rolls initiatives for all registered players. Takes no input."""
     rolltable = fetch_all_data('initiative_register')
     for name, rollstr in rolltable.items():
         for (i, s) in enumerate(rollstr.split(';')):
             s = s.strip()
             cur_name = name
             if i != 0:
                 cur_name = cur_name + '(' + str(i + 1) + ')'
             rolls, constant = rollstrparse(s)
             result = sum(rolls) + constant
             if not write_data('initiative_table', cur_name, result):
                 await ctx.send('Initiative registration failed.')
     await self.printinitiative(ctx)
Exemple #10
0
 async def haxpoints(self, ctx):
     """Gives points to a user. Only usable by Goldilocks. Admin abuse at its best.\nTakes input in the form ?haxpoints recipient_user_id points_to_add."""
     if ctx.message.author.id != str(249293986349580290):
         await ctx.send('Only my maker can hax!')
         return
     try:
         userId = ctx.message.content.split()[1]
         pointNum = int(ctx.message.content.split()[2])
     except Exception:
         await ctx.send('Give the input in an acceptable format you dingus!')
         return
     if fetch_data('points_register', ctx.message.author.id) is None:
         await ctx.send('Coudln\'t find this user in the register!')
         return
     if write_data('points_register', userId, oldPoints + pointNum):
         await ctx.send('Haxing complete.')
     else:
         await ctx.send('Writing data failed, sorry!')
Exemple #11
0
 async def nextplayer(self, ctx):
     """Moves onto next player in intiative order. Takes no input."""
     table = fetch_all_data('initiative_table')
     if table is None:
         await ctx.send('No table saved!')
         return
     cur = None
     vals = [(v, k) for (k, v) in table.items() if k != 'cur']
     vals.sort()
     if 'cur' not in table:
         cur = vals[-1][1]
     else:
         for i in range(len(vals)):
             if vals[i][1] == table['cur']:
                 cur = vals[(i - 1 + len(vals)) % len(vals)][1]
                 break
     if not write_data('initiative_table', 'cur', cur):
         await ctx.send("File IO failed!")
         return
     await ctx.send("It is " + cur + "'s turn!")
     return
Exemple #12
0
 async def rollinitiative(self, ctx):
     """Rolls initiative for the player. Takes no input."""
     namedat = fetch_data('initiative_names', ctx.message.author.id)
     if namedat is None:
         await ctx.send('No initiative name data found!')
         return
     rollstr = fetch_data('initiative_register', namedat)
     if rollstr is None:
         await ctx.send('No initiative bonus data found!')
         return
     name = fetch_data('initiative_names', ctx.message.author.id)
     if name is None:
         name = '{0.mention}'.format(ctx.message.author)
     allres = rollstrtonum(rollstr)
     for (i, x) in enumerate(allres):
         cur_name = name
         if i != 0:
             cur_name = cur_name + '(' + str(i + 1) + ')'
         if not write_data('initiative_table', cur_name, x):
             await ctx.send('Initiative registration failed.')
     await ctx.send('You rolled ' + ';'.join([str(x)
                                              for x in allres]) + '.')