-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcabbage.py
More file actions
117 lines (93 loc) · 2.84 KB
/
cabbage.py
File metadata and controls
117 lines (93 loc) · 2.84 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import cabbagerc
import discord
from discord.ext import commands
from phrasebook.Phrasebook import Phrasebook
from datetime import datetime
cabbageNumber = 2
cabbageStealer = 0
cabbageTheftTime = 0
description = '''Bot That Performs Cabbage-Related Functions'''
bot = commands.Bot(command_prefix=cabbagerc.PREF, description=description)
modules = [
'mod.roller.roller',
'mod.trump.trump',
'mod.admin.admin',
'mod.poll.poll',
'mod.starboard.starboard',
'mod.scp.scp'
]
def autoset():
''' Setup functions '''
global modules
for mod in modules:
bot.load_extension(mod)
def timeStrSince(d):
diff = datetime.now() - d
ts = int(diff.total_seconds())
con = ''
if ts == 0:
return 'just now'
con += str(ts % 60) + ' seconds'
minute = int(ts/60)
if minute == 0:
return con
con = str(minute % 60) + ' minutes and ' + con
hour = int(minute/60)
if hour == 0:
return con
con = str(hour % 24) + ' hours, ' + con
day = hour / 24
if day == 0:
return con
con = str(day) + ' days, ' + con
return con
@bot.event
async def on_ready():
print('CABBAGE IS ONLINE')
print('USER: ' + bot.user.name + ' [' + bot.user.id + ']')
print('=================')
@bot.command(pass_context=True)
async def intro(ctx):
''' Test Command '''
p = Phrasebook(ctx, bot)
await bot.say(p.pickPhrase('core', 'intro1'))
await bot.say(p.pickPhrase('core', 'intro2'))
@bot.command(pass_context=True)
async def cabbages(ctx):
''' Displays the current number of cabbages '''
p = Phrasebook(ctx, bot)
global cabbageNumber
global cabbageStealer
global cabbageTheftTime
print('User ' + str(ctx.message.author) + ' requested cabbage count (currently ' + str(cabbageNumber) + ')')
if datetime.now().hour < 5:
await bot.say(p.pickPhrase('cabbage', 'checkLate'))
return
if cabbageNumber == 0:
await bot.say(p.pickPhrase('cabbage', 'checkOut', cabbageStealer, timeStrSince(cabbageTheftTime)))
else:
await bot.say(p.pickPhrase('cabbage', 'check', cabbageNumber))
@bot.command(pass_context=True)
async def takeCabbage(ctx):
''' Take a cabbage for yourself
Be careful, though: once the cabbages are gone, they're gone until I restart. '''
p = Phrasebook(ctx, bot)
global cabbageNumber
global cabbageStealer
global cabbageTheftTime
print('User ' + str(ctx.message.author) + ' took cabbage (now ' + str(cabbageNumber-1) + ')')
if cabbageNumber > 1:
cabbageNumber = cabbageNumber - 1
if cabbageNumber > 100:
await bot.say(p.pickPhrase('cabbage', 'takePlenty', cabbageNumber))
else:
await bot.say(p.pickPhrase('cabbage', 'take', cabbageNumber))
elif cabbageNumber == 1:
cabbageNumber = 0
await bot.say(p.pickPhrase('cabbage', 'takeLast'))
cabbageStealer = ctx.message.author
cabbageTheftTime = datetime.now()
else:
await bot.say(p.pickPhrase('cabbage', 'checkOut', cabbageStealer.name, timeStrSince(cabbageTheftTime)))
autoset()
bot.run(cabbagerc.TKN)