Skip to content

Commit 804fcc7

Browse files
author
Foxlet
committed
Would You Rather? Alpha - wyr.py
Initial version of this plugin, not PEP-8’d not fully checked.
1 parent b31a815 commit 804fcc7

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

plugins/wyr.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import requests
2+
3+
from cloudbot import hook
4+
5+
headers = {'User-Agent': 'CloudBot/dev 1.0 - CloudBot Refresh by lukeroge'}
6+
7+
@hook.command
8+
def wyr(text, message):
9+
url = "http://www.rrrather.com/botapi"
10+
11+
r = requests.get(url, headers=headers)
12+
data = r.json()
13+
title = data['title'].strip().capitalize()
14+
title = title.rstrip('.?')
15+
choice1 = data['choicea'].strip().lower()
16+
choice1 = choice1.rstrip('.?')
17+
choice2 = data['choiceb'].strip().lower()
18+
choice2 = choice2.rstrip('.?')
19+
link = data['link']
20+
21+
text = "{} {}".format(choice1, choice2).split()
22+
text = [ word for word in text if word != "a" ]
23+
24+
title_text = title.split()
25+
26+
#message(str(title_text))
27+
#message(str(text))
28+
29+
dupl_count = 0
30+
31+
for word in title_text:
32+
dupl_count += text.count(word)
33+
34+
#message(str(dupl_count / len(text)))
35+
36+
if title.lower() == "would u rather":
37+
title = "Would you rather"
38+
39+
if dupl_count / len(text) >= 0.6:
40+
title = "Would you rather"
41+
else:
42+
pass
43+
44+
return "{}... {} \x02OR\x02 {}? - {}".format(title, choice1, choice2, link)

0 commit comments

Comments
 (0)