Skip to content

Commit

Permalink
Delete broken services.nonceword.org commands, migrate simpler ones
Browse files Browse the repository at this point in the history
  • Loading branch information
dpk committed May 21, 2024
1 parent 27030c5 commit 4356c18
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 82 deletions.
15 changes: 0 additions & 15 deletions commands/dety

This file was deleted.

12 changes: 0 additions & 12 deletions commands/lpd

This file was deleted.

13 changes: 0 additions & 13 deletions commands/r2r

This file was deleted.

31 changes: 22 additions & 9 deletions commands/roll
100644 → 100755
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)
20 changes: 13 additions & 7 deletions commands/rot13
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))
13 changes: 0 additions & 13 deletions commands/thesaurus

This file was deleted.

13 changes: 0 additions & 13 deletions commands/weather

This file was deleted.

0 comments on commit 4356c18

Please sign in to comment.