Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 249d7c5
Showing
17 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# GudGuy | ||
|
||
My IRC bot built with [irctk](https://github.com/maxcountryman/irctk) that sits in #tech@nyu on irc.freenode.net and searches the internets for the gud stuff. | ||
Currently searches [Giphy](http://giphy.com), [SoundCloud](http://soundcloud.com), and [YouTube](http://youtube.com). | ||
|
||
* How to add a bot command: | ||
|
||
from gudguy import bot | ||
|
||
@bot.command('mc') # shortcut | ||
@bot.command | ||
def my_command(context): | ||
command = context.args # the command that was issued | ||
return 'Hi.' | ||
|
||
* Then in `gudguy/__init__.py` make sure the module your command was defined in is imported. | ||
* All command must be prefixed with `'.'`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Stuff to implement | ||
------------------ | ||
/r/gifs search | ||
gifbin search |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from irctk import Bot | ||
|
||
from gudguy.config import Config | ||
|
||
# initialize the bot | ||
bot = Bot() | ||
bot.config.from_object(Config) | ||
|
||
# load the plugins | ||
from gudguy import giphy, sc, youtube | ||
|
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
class Config(object): | ||
SERVER = 'irc.freenode.net' | ||
PORT = 6667 | ||
SSL = False | ||
TIMEOUT = 300 | ||
NICK = 'GudGuy' | ||
REALNAME = 'The gud guy.' | ||
CHANNELS = ['#tech@nyu'] | ||
ADMINS = [] | ||
SOUNDCLOUD_CLIENT_ID = '643405e1e13dd4cde125f3379ef36486' |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Consume the Giphy API -- http://giphy.com/ | ||
i.e. 'http://giphy.com/api/gifs?tag=cat' | ||
""" | ||
import random | ||
import requests | ||
import urllib | ||
|
||
from gudguy import bot | ||
from gudguy.utils import timestamp_utcnow | ||
|
||
GIPHY_API = 'http://giphy.com/api' | ||
|
||
|
||
def search_api_url(**kwargs): | ||
endpoint = '/gifs?%s' % (urllib.urlencode(kwargs)) | ||
return GIPHY_API + endpoint | ||
|
||
|
||
def search_api_request(query): | ||
res = requests.get(search_api_url(tag=query)) | ||
return res.json() if res.status_code == 200 else None | ||
|
||
|
||
def search_gifs(query): | ||
content = search_api_request(query) | ||
return content['data'] if content is not None else None | ||
|
||
|
||
def get_gif(gifs, random_gif=False): | ||
if random_gif: | ||
return random.choice(gifs) | ||
return gifs[0] | ||
|
||
|
||
@bot.command('g') | ||
@bot.command | ||
def giphy(context): | ||
query = context.args | ||
opts = {'random_gif': 'random ' in query} | ||
query = query.replace('random ', '') if opts['random_gif'] else query | ||
query = query.replace(' ', '-') | ||
gifs = search_gifs(query) | ||
if not gifs: | ||
return 'Welp.' | ||
return get_gif(gifs, **opts)['thumbnail_url'] |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from gudguy import bot | ||
|
||
import soundcloud | ||
|
||
client = soundcloud.Client(client_id=bot.config['SOUNDCLOUD_CLIENT_ID']) | ||
|
||
|
||
@bot.command('sc') | ||
@bot.command | ||
def soundcloud_track(context): | ||
query = context.args | ||
tracks = client.get('/tracks', q=query) | ||
if not tracks: | ||
return 'Welp.' | ||
track = tracks[0] | ||
return "%s %s" % (track.obj['title'], track.obj['permalink_url']) |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Some utility functions | ||
""" | ||
import time | ||
import datetime | ||
|
||
|
||
def timestamp_utcnow(): | ||
now = datetime.datetime.now() | ||
return time.mktime(now.timetuple()) |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import requests | ||
|
||
from gudguy import bot | ||
|
||
base_url = 'http://gdata.youtube.com/feeds/api/' | ||
search_api_url = base_url + 'videos?v=2&alt=jsonc&max-results=1' | ||
video_url = "http://youtube.com/watch?v={0}" | ||
|
||
|
||
@bot.command('yt') | ||
@bot.command | ||
def youtube_search(context): | ||
res = requests.get(search_api_url, params={'q': context.args}) | ||
if not res.status_code == 200: | ||
return 'Error making request' | ||
|
||
data = res.json() | ||
if 'error' in data: | ||
return 'Error performing search.' | ||
if data['data']['totalItems'] == 0: | ||
return 'No results.' | ||
|
||
video = data['data']['items'][0] | ||
return "%s %s" % (video['title'], video_url.format(video['id'])) |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
IrcTK==0.2.7 | ||
fudge==1.0.3 | ||
pyflakes==0.6.1 | ||
requests==1.1.0 | ||
simplejson==3.1.0 | ||
soundcloud==0.3.6 | ||
wsgiref==0.1.2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from gudguy import bot | ||
|
||
|
||
if __name__ == '__main__': | ||
bot.run() |
Binary file not shown.