-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete broken services.nonceword.org commands, migrate simpler ones
- Loading branch information
Showing
7 changed files
with
35 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# http://inamidst.com/saxo/ | ||
# Created by Sean B. Palmer | ||
import random | ||
import re | ||
|
||
import urllib.parse | ||
import saxo | ||
|
||
|
||
@saxo.pipe | ||
def roll(arg): | ||
if not arg: | ||
return "Let me roll it" | ||
arg = urllib.parse.quote(arg) | ||
page = saxo.request("http://services.nonceword.org/p/roll/{}".format(arg)) | ||
return page["text"] | ||
def roll(dice): | ||
m = re.match(r"(\d+)d(\d+)", dice) | ||
if not m: return 'e.g. .roll 1d12' | ||
number, sides = map(int, m.groups()) | ||
if number > 20: return 'Sorry, you can only roll up to 20 dice at a time.' | ||
if sides > 100: return 'Sorry, I only have dice with sides up to 100.' | ||
def do_roll(number, sides): | ||
results = tuple(random.randint(1, sides) for die in range(number)) | ||
if number == 1: | ||
if sides == 2: | ||
return ['heads', 'tails'][results[0] - 1] | ||
else: | ||
return str(results[0]) | ||
else: | ||
if sides == 2: | ||
return ', '.join(['heads', 'tails'][result - 1] for result in results) | ||
else: | ||
return '%s = %s' % (' + '.join(str(result) for result in results), sum(results)) | ||
return do_roll(number, sides) |
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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# http://inamidst.com/saxo/ | ||
# Created by Sean B. Palmer | ||
import unicodedata as u | ||
|
||
import urllib.parse | ||
import saxo | ||
|
||
|
||
def cipher_char(char): | ||
ascii_value = ord(char) | ||
if 97 <= ascii_value < 123: | ||
return chr(97 + (((ascii_value - 97) + 13) % 26)) | ||
elif 65 <= ascii_value < 91: | ||
return chr(65 + (((ascii_value - 65) + 13) % 26)) | ||
else: | ||
return char | ||
|
||
@saxo.pipe | ||
def rot13(arg): | ||
arg = urllib.parse.quote(arg) | ||
page = saxo.request("http://services.nonceword.org/p/rot13/" + arg) | ||
return page["text"] | ||
def _rot13(text): | ||
return ''.join(cipher_char(char) for char in u.normalize('NFD', text)) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.