-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmonitorwords.py
More file actions
242 lines (217 loc) · 10.2 KB
/
monitorwords.py
File metadata and controls
242 lines (217 loc) · 10.2 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import requests
import plugins
import os
from random import *
import emoji
import pprint
import json
from plugins.__nhlbot import *
import re
from webpreview import web_preview
from bs4 import BeautifulSoup
"""
the web url matching regex used by markdown
http://daringfireball.net/2010/07/improved_regex_for_matching_urls
https://gist.github.com/gruber/8891611
"""
URL_REGEX = r"""(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)\b/?(?!@)))"""
def format_stats(stats):
output = ''
for key, value in stats.items():
output += "{} : {}\n".format(str(key), str(value))
return output
def get_meekle_stats():
os_dropped = randint(1, 10)
shirts_off = randint(1, 50)
seinfelds_watched = 0
spillzones = randint(1, 500)
petite_redheads = randint(1, 150)
result = """Os dropped: {}\n Shirts Off: {}
Seinfelds Watched: {}\n Spillzones: {}
Petite Redheads: {}\n""".format(os_dropped,
shirts_off,
seinfelds_watched,
spillzones,
petite_redheads)
return result
def get_joeyboy_stats():
woman_wooed = randint(1, 10)
mountain_mommas = randint(1, 200)
sister_mommas = randint(1, 100)
thottsexckx = randint(1, 10)
result = """Women wooed: {}\n Mountain Mommas: {}
SisterMommas: {}\n thottsexckx: {}\n""".format(
woman_wooed, mountain_mommas,
sister_mommas,
thottsexckx)
return result
def get_nhl_scores():
all_games = ''
try:
result = requests.get(
"https://statsapi.web.nhl.com/api/v1/schedule").json()
games = result['dates'][0]['games']
for game in games:
away = "{} {}\n".format(
game['teams']['away']['team']['name'],
game['teams']['away']['score'])
home = "{} {}\n".format(
game['teams']['home']['team']['name'],
game['teams']['home']['score'])
score = away+home
all_games += score + '\n'
except IndexError:
all_games = 'No games scheduled for today'
return all_games
def get_nhl_team_stats(name):
result = format_stats(get_team_stats(
name)['stats'][0]['splits'][0]['stat'])
result += format_stats(get_team_stats(name)
['stats'][1]['splits'][0]['stat'])
return result
def parse_twitter(url):
try:
if 'mobile.twitter.com' in url:
result = requests.get(url, allow_redirects=True)
if 'Redirecting you to' in result.text:
url = re.findall('Redirecting you to (.*)<\/BODY>',result.text)[0]
else:
result = requests.get(url)
soup = BeautifulSoup(result.text, 'html.parser')
description = soup.body.find_all('div',{"class":"tweet-text"})[0].div.contents[0].strip()
return f"Twitter\n{description}"
else:
title, description, image = web_preview(url)
return f"Twitter\n{description}"
except Exception as ex:
print(ex)
def url_preview(urls):
result = []
for url in urls:
try:
if 'youtube' in url:
break
elif 'googleusercontent.com' in url:
break
elif 'twitter.com' in url:
result = parse_twitter(url)
result.append(result)
else:
headers = {'User-Agent': 'Mozilla/5.0'}
title, description, image = web_preview(url,headers=headers)
if not title or not description:
return []
result.append(f"{title}\n{description}\n")
except Exception as ex:
print(f"unable to parse {url} {ex}")
return result
def aoe_times():
play_times = ["8pm", "9pm", "10pm", "now"]
random_index = randrange(len(play_times)-1)
return play_times[random_index]
def _initialise(bot):
plugins.register_handler(_got_a_message, type="message",
priority=50)
def _got_a_message(bot, event, command):
result = re.findall(URL_REGEX,event.text)
if len(result)>0:
message = url_preview(result)
if len(message)>0:
yield from bot.coro_send_message (
event.conv,
_("".join(str(x) for x in message)))
if "joeyfluff" in event.text.lower():
yield from bot.coro_send_message(
event.conv,
_("YOU SAID THE SECRET WORDDDDDD {}!!!").format(
event.user.full_name, 'yay'))
elif event.text.lower() == "tom bomb":
yield from bot.coro_send_message(
event.conv,
_('Gary actually made the tom bomb. {}'.format(
emoji.emojize(':poop::poop::poop::poop::poop::poop:' +
':poop::poop::poop::poop::poop::poop:' +
':poop::poop::poop:', use_aliases=True))))
elif event.text.lower() == 'when palooza':
yield from bot.coro_send_message(
event.conv,
_('Toomie picked May 28!'))
elif event.text.lower() == 'when aoe':
yield from bot.coro_send_message(
event.conv,
_(aoe_times()))
elif event.text.lower() == 'where palooza':
yield from bot.coro_send_message(
event.conv,
_("I believe it is Miller's turn to pick"))
elif event.text.lower() == 'where miller kielbasa':
yield from bot.coro_send_message(
event.conv,
_("Oh, its somewhere you don't wanna know.... :-;"))
elif event.text.lower() == 'how many socks':
yield from bot.coro_send_message(
event.conv,
_("Meekle uses %s socks" % randint(1, 100)))
elif event.text.lower() == 'how many kielbasa':
yield from bot.coro_send_message(
event.conv,
_("Miller scarfs down %s kielbasa" % randint(1, 100)))
elif "!nhl" in event.text.lower():
action = event.text.lower().split('!nhl ')[1]
if action.lower() == 'scores':
#text = get_nhl_scores()
text = get_scores()
yield from bot.coro_send_message(
event.conv,
_(text))
elif action.startswith('stats'):
try:
print(action)
team = action.split('stats ')[1]
print('Getting team {}'.format(team))
result = get_nhl_team_stats(team)
yield from bot.coro_send_message(
event.conv,
_(result))
except Exception as e:
print(e)
yield from bot.coro_send_message(
event.conv,
_('Please pass team name {}'.format(e)))
elif "!stats" in event.text.lower():
person = event.text.lower().split('!stats ')[1]
if person.lower() == 'joeyboy':
text = get_joeyboy_stats()
yield from bot.coro_send_message(
event.conv,
_(text))
if person.lower() == 'meekle':
text = get_meekle_stats()
yield from bot.coro_send_message(
event.conv,
_(text))
elif "!joeyboy" in event.text.lower():
from random import randrange
random_index = randrange(0, 3)
if random_index == 2:
try:
site_url = bot.get_config_option('posseimage_url')
instanceImageUrl = site_url+'/joey/jodyboy.jpg'
photo_id = yield from bot.call_shared('image_upload_single',
instanceImageUrl)
yield from bot.coro_send_message(event.conv.id_, '',
image_id=photo_id)
except Exception as e:
print(e)
else:
script_dir = os.path.dirname(__file__)
rel_path = "joeyboy.txt"
joeyboywords_path = os.path.join(script_dir, rel_path)
words = open(joeyboywords_path, 'r')
words = words.read()
words = words.splitlines()
random_index = randrange(0, len(words))
random_word = words[random_index]
yield from bot.coro_send_message(
event.conv,
_(random_word))