-
Notifications
You must be signed in to change notification settings - Fork 0
/
isfoxonitbot.py
executable file
·176 lines (142 loc) · 6.14 KB
/
isfoxonitbot.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
"""Fox is on it bot. Reports foxy's drinking status."""
import logging
import os
import random
from datetime import datetime, timedelta
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - '
'%(message)s')
LOGGER = logging.getLogger(__name__)
TOKEN = "358070225:AAFKiJ7LlmwpVt5MqyYbzcA4tW4TVvOkyew"
THIRSTY = ["Dying for a beer", 'Will suck fatz for a pint',
"This sun makes me want a beer.", "Anything makes me want a beer.",
"12% body fat or beer? It's getting harder to choose.",
"Don't speak to me I'm sober.", "Sparkly water please.",
"I am sooo boring without beer", "I look so old when I am sober",
"Need a beer to wash down Fatz's tonsil glaze.",
"Did I say I'm off the booze?", "Pulling nose hairs.",
"Sewing buttons on my XXS shirt.",
"Updating my status on Facebook cause "
"I'm not drinking don't you know",
'Been off it for {} days, that must deserve a kiss.'.format
(random.randrange(1, 50)),
"Getting boat home, could kill a beer on the boat.",
"This rain is making me thirsty.", "One fucking week to go...",
"New office has a pub, booze free time is not going to last.",
"Trains all delayed by an hour now ffs, drive a man to drink.",
"Who needs beer anyway?"]
DRINK = ["Pissed as a fart.", "Get to the bar, cnut.",
"Call me an Uber I need a sleep outside of my front door.",
"Uber, uber, on no, Uber is suspended, how is it possible to get home now?",
"Look Da I'm making the most of a terroist incident by getting on "
"telly pissed.",
"Droney droney droney... tree tree tree!!! Feck!!!",
"Hey Guarda, you're a bastard and a fat cunt",
"Ah Guiness. The farts of the gods."]
mThirsty = THIRSTY.copy()
mDrink = DRINK.copy()
myState = "thirsty"
def gcloud_envs_print():
"""Print GAE env variables."""
gcloud_envs = ['GAE_INSTANCE', 'GAE_MEMORY_MB', 'GAE_VERSION', 'PORT',
'GCLOUD_PROJECT', 'GAE_SERVICE']
output = ""
for genv in gcloud_envs:
if genv in os.environ:
output = output + genv + ": " + os.environ[genv] + "\n"
return output
def usage():
"""Return usage message."""
return (
"Send me a message:\n\n*/dyingtoknow@IsFoxOnItBot* - "
"Update on how long for a drink.\n\nTry me a few times, "
"you never know what you'll get!\n")
def sothirsty():
"""Provide a semi random thirsty quote."""
global mThirsty
print(mThirsty)
if len(mThirsty) == 0:
mThirsty = THIRSTY.copy()
quote = mThirsty[random.randrange(0, len(mThirsty))]
mThirsty.remove(quote)
print(mThirsty)
return quote
def drinking():
"""Provide a semi-random drinking quote."""
global mDrink
print(mDrink)
if len(mDrink) == 0:
mDrink = DRINK.copy()
quote = mDrink[random.randrange(0, len(mDrink))]
mDrink.remove(quote)
print(mDrink)
return quote
def start(bot, update):
"""Get the bot going."""
update.message.reply_text("*Hi*", parse_mode="Markdown")
def help_isfoxonit(bot, update):
"""Message for help or not understood."""
update.message.reply_text("I don't know what you mean you obtuse Manny.\n"
+ usage(), parse_mode="Markdown")
def bot_error(bot, update, error):
"""Log a generic error."""
#LOGGER.warning('Update "%s" caused error "%s"' % (update, error))
LOGGER.warning("Update %s caused error %s", update, error)
def switch(bot, update):
"""Toggle foxy's state."""
LOGGER.debug("Switch: %s", update)
global myState
if myState == "thirsty":
myState = "pissed"
update.message.reply_text("Switched from thirsty to "
+ myState + ".\n", parse_mode="Markdown")
else:
myState = "thirsty"
update.message.reply_text("Switched from pissed to "
+ myState + ".\n", parse_mode="Markdown")
def dyingtoknow(bot, update):
"""Return info on foxy's drinking status."""
LOGGER.info('dyingtoknow')
today = datetime.today()
target = datetime(year=2017, month=10, day=1, hour=17, minute=0, second=0)
remaining = target - today
if remaining <= timedelta(0) or myState == "pissed":
update.message.reply_text("*Time for drinkies!*\n\n*Foxy's status:*\n_"
+ drinking() + "_", parse_mode="Markdown")
else:
update.message.reply_text(
"*Foxy's status:\n*_" + sothirsty() + "_"
+ "\n\n" + "*Time remaining:\n*" + "_Fatz Style:_ "
+ str(remaining), parse_mode="Markdown")
def print_sysinfo(bot, update):
"""Print out some sysinfo."""
import sysinfo
LOGGER.info(str("\n" + sysinfo.sysinfo() + "\n" + gcloud_envs_print()))
update.message.reply_text(sysinfo.sysinfo())
def main():
"""Start bot, tell Telegram."""
port = int(os.environ.get('PORT', '5000'))
# Create the EventHandler and pass it your bot's token.
updater = Updater(TOKEN)
# Get the dispatcher to register handlers
fox_dispatcher = updater.dispatcher
# on different commands - answer in Telegram
fox_dispatcher.add_handler(CommandHandler("start", start))
fox_dispatcher.add_handler(CommandHandler("help", help_isfoxonit))
fox_dispatcher.add_handler(CommandHandler("dyingtoknow", dyingtoknow))
fox_dispatcher.add_handler(CommandHandler("switch", switch))
fox_dispatcher.add_handler(CommandHandler("sysinfo", print_sysinfo))
# on noncommand i.e message - echo the message on Telegram
fox_dispatcher.add_handler(MessageHandler(Filters.text, help))
# log all errors
fox_dispatcher.add_error_handler(bot_error)
# add handlers
updater.start_webhook(listen="0.0.0.0",
port=port,
url_path=TOKEN)
updater.bot.set_webhook("https://isfoxonit.duckdns.org/" + TOKEN)
updater.idle()
if __name__ == '__main__':
"""Main."""
main()