Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Commit

Permalink
Standardize bot pastebin usage, add pastebin selection to config
Browse files Browse the repository at this point in the history
  • Loading branch information
clsr committed May 23, 2016
1 parent b1a414d commit c1b08a9
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -215,7 +215,7 @@ A module for automatically replying to things that are said in the channel. Also

```
# Admin-only commands:
list replies # lists replies and uploads them to sprunge.us for easy viewing
list replies # lists replies and uploads them to a pastebin for easy viewing
stop that # stops the bot from triggering
yes, stop that # really stops the bot from triggering (can only be used after stop that)
remove reply to [trigger] # stops the bot from triggering without asking for confirmation
Expand Down
3 changes: 3 additions & 0 deletions config-example.py
Expand Up @@ -33,6 +33,9 @@
DB_PASSWORD = ""
DB_DATABASE = "bhottu"

#The pastebin to use (available: sprunge, nnmm, sicpme, ix)
PASTEBIN = 'nnmm'

#recommended modules. For more, browse modules/. There is documentation about writing them in the README and the default ones serve as good examples
ENABLED_MODULES = [
'Admins',
Expand Down
4 changes: 2 additions & 2 deletions modules/books.py
Expand Up @@ -23,13 +23,13 @@ def addBook(channel, sender, booktitle):

@register("dumpbooks", syntax="dumpbooks")
def allBooks(channel, sender):
"""Fetches all books in database, upload them on nnmml or whatever, not featured not scalable fuckyou"""
"""Fetches all books in database, upload them on a pastebin, not featured not scalable fuckyou"""
books = dbQuery('SELECT title, added_by FROM books')
bookList = ''
for (title, added_by) in books:
bookList += '\"%s\" inserted by \"%s\"\n' % (title, added_by)
try:
url = nnmm(bookList)
url = paste(bookList)
except Exception:
sendMessage(channel, "Uploading book list failed.")
return
Expand Down
4 changes: 2 additions & 2 deletions modules/help.py
Expand Up @@ -28,7 +28,7 @@ def help(channel, sender, command):
msg_lines.append(command_line)
msg_lines.append("You can use `help <command>` for specific help.")
msg = "\n\n".join(msg_lines)
url = pastebins.sprunge(msg)
url = pastebins.paste(msg)
sendMessage(channel, "{}: {}".format(sender, url))

else:
Expand All @@ -43,4 +43,4 @@ def help(channel, sender, command):
helpProvided = True
if helpProvided:
return
sendMessage(sender, "I have no help on that topic.")
sendMessage(sender, "I have no help on that topic.")
2 changes: 1 addition & 1 deletion modules/ignore.py
Expand Up @@ -51,7 +51,7 @@ def listIgnores(channel, sender):
for (nick, issuer, issuetime) in dbQuery("SELECT nick, issuer, issuetime FROM ignores"):
ignores.append("%s: set by %s on %s" % (nick, issuer, time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(issuetime))))
try:
url = nnmm('\n'.join(ignores))
url = pastebin('\n'.join(ignores))
sendMessage(channel, "The following people are currently ignored: %s" % url)
except Exception as e:
sendMessage(channel, "Uploading list of ignored people failed: %s" % (e,))
4 changes: 2 additions & 2 deletions modules/linktitle.py
Expand Up @@ -110,7 +110,7 @@ def showAllLinks(channel, sender, searchterm):
for link in links:
linklist += "%s : %s\n" % (link[0], link[1])
try:
url = sprunge(linklist)
url = paste(linklist)
except:
log.warning('Failed to upload link list')
sendMessage(channel, "Error uploading link list")
Expand All @@ -123,7 +123,7 @@ def showBlacklist(channel, sender):
for domain in dbQuery('SELECT domain FROM blacklists'):
blacklist += domain[0] + "\n"
try:
url = sprunge(blacklist)
url = paste(blacklist)
except:
log.warning('Failed to upload blacklist')
sendMessage(channel, "Error uploading blacklist")
Expand Down
2 changes: 1 addition & 1 deletion modules/quotes.py
Expand Up @@ -71,7 +71,7 @@ def allQuotes(channel, sender, target):
for quote in quotes:
quoteList += '<%s> %s\n' % (target, quote[0])
try:
url = nnmm(quoteList)
url = paste(quoteList)
except Exception:
sendMessage(channel, "Uploading quotes for %s failed." % target)
return
Expand Down
4 changes: 2 additions & 2 deletions modules/reply.py
Expand Up @@ -86,7 +86,7 @@ def listReplies(channel, sender):
for reply in replies:
replyList += '%s <reply> %s\n' % (reply[0], reply[1])
try:
url = sprunge(replyList)
url = paste(replyList)
except Exception:
sendMessage(channel, "Uploading replies failed.")
return
Expand Down Expand Up @@ -152,7 +152,7 @@ def listBannedTriggers(channel, sender):
for trigger in triggers:
triggerList += trigger[0] + '\n'
try:
url = sprunge(triggerList)
url = paste(triggerList)
except Exception:
sendMessage(channel, "Uploading banned triggers failed.")
return
Expand Down
4 changes: 2 additions & 2 deletions modules/threadsearch.py
Expand Up @@ -8,7 +8,7 @@
import requests
import traceback
from api import *
from utils.pastebins import nnmm
from utils.pastebins import paste
from time import sleep
from threading import *
from collections import deque
Expand Down Expand Up @@ -52,7 +52,7 @@ def process_results(channel, sender, results_data):
post_template = "https://boards.4chan.org/{0}/thread/{1}"
urls = [post_template.format(search_parameters["board"], post_num) for post_num in post_numbers]
if len(urls) > max_num_urls_displayed:
message = nnmm('\n'.join(urls))
message = paste('\n'.join(urls))
else:
message = " ".join(urls[:max_num_urls_displayed])
sendMessage(channel, "{0}: {1} | Search time {2:.2f}s | {3} matches".format(sender, message, total_time, len(urls)))
Expand Down
21 changes: 18 additions & 3 deletions utils/pastebins.py
@@ -1,14 +1,29 @@
#!/usr/bin/env python
import requests, urllib2
import config

def paste(data):
if config.PASTEBIN == 'sprunge':
return sprunge(data)
if config.PASTEBIN == 'nnmm':
return nnmm(data)
if config.PASTEBIN == 'sicpme':
return sicpme(data)
if config.PASTEBIN == 'ix':
return ix(data)
raise NotImplementedError

def sprunge(data):
sprunge_data = {"sprunge": data}
response = requests.post("http://sprunge.us", data=sprunge_data)
message = response.text.encode().strip('\n')
return message

def pastebin(data):
raise NotImplementedError

def nnmm(data):
return urllib2.urlopen("https://nnmm.nl", data).read()

def sicpme(data):
return requests.post('https://sicp.me/', data={'paste': data}).text.encode().strip('\r\n')

def ix(data):
return requests.post('http://ix.io/', data={'f:1': data}).text.encode().strip('\r\n')

0 comments on commit c1b08a9

Please sign in to comment.