forked from tangotrail/catsite-stork-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cats.py
84 lines (66 loc) · 2.24 KB
/
cats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import logging
from discord.ext import commands
logger = logging.getLogger('discord')
logger.setLevel(logging.INFO)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
class Cats(commands.Cog):
def __init__(self, bot):
self.bot = bot
with open('settings.json', 'r') as f:
content = json.load(f)
self.color = int(content['color'][2:], base=16)
self.admin_ids = [int(discid) for discid in content['permissions']['admins']]
@commands.command()
async def mayor(self, ctx, *, contents):
# wipe original msg b/c it is v long
await ctx.message.delete()
lines = [line for line in contents.split('\n') if line]
total = 0
boosted = False
summary = ''
for i, stat in enumerate(get_stat_nicks()):
num = int(lines[i * 5 + 1])
total += num
boost = get_mayor_boost(num)
summary += f'{get_stat_color(num)} {stat} {num} '
if boost:
summary += f'***+{boost}*** '
boosted = True
if i == 3:
summary += '\n'
out = f'{ctx.message.author.mention} Stat total: **{total}**\n{summary}\n'
if not boosted:
out += 'This cat provides no mayor boosts.'
await ctx.send(out)
async def setup(bot):
logger.info("Loaded cats.py")
await bot.add_cog(Cats(bot))
def thresholds(inputs, overflow):
def threshold_f(num):
for max_num, output in inputs:
if num <= max_num:
return output
return overflow
return threshold_f
def get_mayor_boost(num):
f = thresholds([
(18, 0),
(22, 1),
(26, 2),
(30, 3),
], 4)
return f(num)
def get_stat_color(num):
f = thresholds([
(6, '🔴'),
(12, '🟠'),
(16, '🟡'),
(20, '🟢'),
(24, '🔵'),
], '🟣')
return f(num)
def get_stat_nicks():
return ['STR', 'AGI', 'HLT', 'FIN', 'CLV', 'PRC', 'LCK']