bitbot-3.11-fork/modules/hash.py

25 lines
922 B
Python
Raw Normal View History

#--depends-on commands
2016-04-20 12:52:23 +00:00
import hashlib
from src import ModuleManager, utils
2016-04-20 12:52:23 +00:00
class Module(ModuleManager.BaseModule):
@utils.hook("received.command.hash", remove_empty=False)
2016-04-20 12:52:23 +00:00
def hash(self, event):
"""
:help: Hash a given string with a given algorithm
:usage: <algo> <string>
"""
if event["args_split"]:
algorithm = event["args_split"][0].lower()
2016-04-20 12:52:23 +00:00
phrase = " ".join(event["args_split"][1:])
if algorithm in hashlib.algorithms_available:
cipher_text = hashlib.new(algorithm, phrase.encode("utf8")
).hexdigest()
event["stdout"].write("%s -> %s" % (phrase, cipher_text))
else:
event["stderr"].write("Unknown algorithm provided")
2016-04-20 12:52:23 +00:00
else:
event["stdout"].write("Available algorithms: %s" %
", ".join(hashlib.algorithms_available))