Created
January 23, 2015 19:16
-
-
Save LordAro/1c01e8fc8df04d85b26d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import random | |
import re | |
import requests | |
from csbot.plugin import Plugin | |
from csbot.util import nick, simple_http_get | |
def get_title(issue_id): | |
try: | |
url = "https://code.google.com/p/freerct/issues/csv?can=1&q=id:{}".format(issue_id) | |
response = simple_http_get(url) | |
if response.status_code != requests.codes.ok: | |
return | |
cr = csv.reader(response.text.splitlines()) | |
for row in list(cr): | |
if row[0] == str(issue_id): | |
return row[5] | |
except (IndexError, KeyError) as ex: | |
print("Error getting issue title:" + str(ex)) | |
responses = [ | |
"I want to go on something more thrilling than ${RIDE}.", | |
"I want to get off Mr. Bones' Wild Ride.", | |
"This park is really clean and tidy.", | |
"I want to go home.", | |
"Help! I'm drowning!", | |
"Guest ${NUM} is lost and can't find the park exit.", | |
"${STR} is lost and can't find the park exit.", | |
"I'm lost!", | |
"I've been queuing for ${RIDE} for ages.", | |
"I have the strangest feeling someone is watching me", | |
"I feel sick!", | |
"I feel very sick!", | |
"I've spent all my money.", | |
"${RIDE} looks too intense for me!", | |
] | |
rides = [ | |
"Merry-Go-Round 1", | |
"Mr. Bones' Wild Ride", | |
"Roller Coaster 1", | |
] | |
class FreeRCT(Plugin): | |
@Plugin.hook('core.message.privmsg') | |
def annoyance(self, e): | |
if "think" not in e["message"] and "thought" not in e["message"]: | |
return | |
if random.randint(0, 10) != 0: | |
return | |
string = random.choice(responses) | |
string = string.replace("${NUM}", str(random.randint(1, 1000))) | |
string = string.replace("${STR}", nick(e["user"])) | |
string = string.replace("${RIDE}", random.choice(rides)) | |
e.protocol.msg(e["reply_to"], string) | |
@Plugin.command('blog') | |
def blog(self, e): | |
e.protocol.msg(e["reply_to"], "[ FreeRCT DevBlog ] - http://freerct.blogspot.co.uk") | |
@Plugin.command('code') | |
def code(self, e): | |
e.protocol.msg(e["reply_to"], "[ FreeRCT Googlecode ] - http://freerct.googlecode.com") | |
@Plugin.command('github') | |
def github(self, e): | |
e.protocol.msg(e["reply_to"], "[ FreeRCT Github ] - http://github.com/FreeRCT/FreeRCT") | |
@Plugin.command('group') | |
def group(self, e): | |
e.protocol.msg(e["reply_to"], "[ FreeRCT Google Group ] - http://groups.google.com/d/forum/freerctgame") | |
@Plugin.command('fyt') | |
def youtube(self, e): | |
e.protocol.msg(e["reply_to"], "[ FreeRCT Youtube ] - http://youtube.com/FreeRCTGame") | |
@Plugin.hook('core.message.privmsg') | |
def issues(self, e): | |
m = re.search(".*#([0-9]+)", e["message"]) | |
if not m: | |
return | |
url = "https://code.google.com/p/freerct/issues/detail?id={}" | |
issue_id = m.group(1) | |
url = url.format(issue_id) | |
title = get_title(int(issue_id)) | |
if not title: | |
return | |
message = "[ {} ] - {}".format(title, url) | |
e.protocol.msg(e["reply_to"], message) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment