Compare commits

..

No commits in common. "d8caed033ee5e34e6ef4bb2aaf42ba88e342cba6" and "2397ded4b581d79da7fa724105365d7367f8772d" have entirely different histories.

7 changed files with 19 additions and 45 deletions

2
bot.py
View File

@ -173,7 +173,7 @@ class Fulvia(irc.IRCClient):
self._hooks.remove(func) self._hooks.remove(func)
if func.rate or func.channel_rate or func.global_rate: if func.rate or func.channel_rate or func.global_rate:
self._times.pop(func.__name__) self._times.pop(func)
if hasattr(func, 'url_callback'): if hasattr(func, 'url_callback'):
for url in func.url_callback: for url in func.url_callback:

View File

@ -3,6 +3,7 @@
ASCII ASCII
""" """
from io import BytesIO from io import BytesIO
import argparse
import requests import requests
from PIL import Image, ImageFont, ImageDraw from PIL import Image, ImageFont, ImageDraw
@ -10,7 +11,6 @@ from PIL import Image, ImageFont, ImageDraw
import numpy as np import numpy as np
import numpngw import numpngw
import tools
import module import module
ASCII_CHARS = "$@%#*+=-:. " ASCII_CHARS = "$@%#*+=-:. "
@ -235,7 +235,7 @@ def ascii(bot, trigger):
""" """
if len(trigger.args) < 2: if len(trigger.args) < 2:
return bot.msg() return bot.msg()
parser = tools.FulviaArgparse() parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("imagePath") parser.add_argument("imagePath")
parser.add_argument("-r", "--reverse", action="store_true", help="Reverse.") parser.add_argument("-r", "--reverse", action="store_true", help="Reverse.")
parser.add_argument("-c", "--color", action="store_true") parser.add_argument("-c", "--color", action="store_true")
@ -243,10 +243,10 @@ def ascii(bot, trigger):
parser.add_argument("-B", "--brail2", action="store_true") parser.add_argument("-B", "--brail2", action="store_true")
parser.add_argument("-a", "--animated", action="store_true") parser.add_argument("-a", "--animated", action="store_true")
parser.add_argument("-h", "--help", action="store_true") parser.add_argument("-h", "--help", action="store_true")
try:
args = parser.parse_args(trigger.args[1:]) args = parser.parse_args(trigger.args[1:])
except Exception as e:
return bot.reply(type(e).__name__ + ": " + str(e)) if args.help:
return bot.msg(parser.print_help())
if args.color: if args.color:
args.color = "irc" args.color = "irc"

View File

@ -3,8 +3,8 @@
Resistor color band codes. Resistor color band codes.
""" """
import re import re
import argparse
import tools
from module import commands, example from module import commands, example
suffix = {"k": 1000, "m": 10000000} suffix = {"k": 1000, "m": 10000000}
@ -62,14 +62,11 @@ def resist(bot, trigger):
""" """
if len(trigger.args) < 2: if len(trigger.args) < 2:
return bot.msg("Please specify a value") return bot.msg("Please specify a value")
parser = tools.FulviaArgparse() parser = argparse.ArgumentParser()
parser.add_argument("value", nargs="+") parser.add_argument("value", nargs="+")
parser.add_argument("-r", "--reverse", action="store_true") parser.add_argument("-r", "--reverse", action="store_true")
parser.add_argument("-n", "--num_bands", type=int, choices=[3,4,5,6], default=4) parser.add_argument("-n", "--num_bands", type=int, choices=[3,4,5,6], default=4)
try:
args = parser.parse_args(trigger.args[1:]) args = parser.parse_args(trigger.args[1:])
except Exception as e:
return bot.reply(type(e).__name__ + ": " + str(e))
if args.reverse: # bands-to-value if args.reverse: # bands-to-value
bot.msg(bands_to_value(" ".join(args.value))) bot.msg(bands_to_value(" ".join(args.value)))

View File

@ -4,13 +4,13 @@ When was this user last seen.
""" """
import os import os
import time import time
import argparse
import threading import threading
from datetime import datetime from datetime import datetime
from sqlite3 import OperationalError from sqlite3 import OperationalError
from requests.structures import CaseInsensitiveDict from requests.structures import CaseInsensitiveDict
import tools
import config import config
from tools.time import relativeTime from tools.time import relativeTime
from module import commands, example, hook, require_chanmsg, rate from module import commands, example, hook, require_chanmsg, rate
@ -68,16 +68,13 @@ def seen(bot, trigger):
if len(trigger.args) < 2: if len(trigger.args) < 2:
return bot.reply("Seen who?") return bot.reply("Seen who?")
parser = tools.FulviaArgparse() parser = argparse.ArgumentParser()
parser.add_argument("nick") parser.add_argument("nick")
parser.add_argument("-l", "--last", action="store_true", default=True) parser.add_argument("-l", "--last", action="store_true", default=True)
parser.add_argument("-f", "--first", action="store_true") parser.add_argument("-f", "--first", action="store_true")
parser.add_argument("-m", "--message", action="store_true") parser.add_argument("-m", "--message", action="store_true")
parser.add_argument("-c", "--context", action="store_true") parser.add_argument("-c", "--context", action="store_true")
try:
args = parser.parse_args(trigger.args[1:]) args = parser.parse_args(trigger.args[1:])
except Exception as e:
return bot.reply(type(e).__name__ + ": " + str(e))
if args.nick == bot.nick: if args.nick == bot.nick:
return bot.reply("I'm right here!") return bot.reply("I'm right here!")

View File

@ -5,8 +5,8 @@ All data comes from http://www.rsdb.org/.
""" """
import random import random
import sqlite3 import sqlite3
import argparse
import tools
from module import commands from module import commands
@ -33,14 +33,11 @@ def slur(bot, trigger):
-s, --slur - specifies a particular slur to pick. -s, --slur - specifies a particular slur to pick.
-l, --list - prints a list of available races. -l, --list - prints a list of available races.
""" """
parser = tools.FulviaArgparse() parser = argparse.ArgumentParser()
parser.add_argument("-r", "--race", type=str, nargs='+') parser.add_argument("-r", "--race", type=str, nargs='+')
parser.add_argument("-s", "--slur", type=str) parser.add_argument("-s", "--slur", type=str)
parser.add_argument("-l", "--list", action="store_true") parser.add_argument("-l", "--list", action="store_true")
try:
args = parser.parse_args(trigger.args[1:]) args = parser.parse_args(trigger.args[1:])
except Exception as e:
return bot.reply(type(e).__name__ + ": " + str(e))
if args.list: if args.list:
races = bot.db.execute("SELECT DISTINCT race FROM slur").fetchall() races = bot.db.execute("SELECT DISTINCT race FROM slur").fetchall()

View File

@ -3,10 +3,10 @@
Google translate that shit. Google translate that shit.
""" """
import random import random
import argparse
import requests import requests
import tools
from module import commands, example from module import commands, example
@ -45,14 +45,11 @@ def tr2(bot, trigger):
if len(trigger.args) < 2: if len(trigger.args) < 2:
return bot.reply("Translate what?") return bot.reply("Translate what?")
parser = tools.FulviaArgparse() parser = argparse.ArgumentParser()
parser.add_argument("text", nargs=argparse.REMAINDER) parser.add_argument("text", nargs=argparse.REMAINDER)
parser.add_argument("-i", "--inlang", default="auto") parser.add_argument("-i", "--inlang", default="auto")
parser.add_argument("-o", "--outlang", default="en") parser.add_argument("-o", "--outlang", default="en")
try:
args = parser.parse_args(trigger.args[1:]) args = parser.parse_args(trigger.args[1:])
except Exception as e:
return bot.reply(type(e).__name__ + ": " + str(e))
args.text = " ".join(args.text) args.text = " ".join(args.text)
tr_text, in_lang = translate(args.text, in_lang=args.inlang, tr_text, in_lang = translate(args.text, in_lang=args.inlang,

View File

@ -3,7 +3,6 @@
Some helper functions and other tools. Some helper functions and other tools.
""" """
import re import re
import argparse
import threading import threading
from collections import defaultdict from collections import defaultdict
@ -200,16 +199,3 @@ def getOpSym(level):
return "+" return "+"
else: else:
return " " return " "
class FulviaArgparse(argparse.ArgumentParser):
"""
A custom ArgParser class that raises errors as exceptions rather than
printing them to stderr.
"""
def __init__(self, *args, **kwargs):
kwargs['add_help'] = False
super().__init__(*args, **kwargs)
def error(self, message):
raise argparse.ArgumentError(None, message)