A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

44 satır
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Cryptography functions (hashing and cyphers).
  3. import hashlib
  4. from irc.base_command import BaseCommand
  5. class Calc(BaseCommand):
  6. def get_hooks(self):
  7. return ["msg"]
  8. def get_help(self, command):
  9. if command == "hash":
  10. return ("Return the hash of a string using a given algorithm, " +
  11. "e.g. '!hash sha512 Hello world!'.")
  12. else:
  13. return ("{0} a string with a given key using a given algorithm, " +
  14. "e.g. '!{1} blowfish some_key Hello world!'.").format(
  15. command.capitalize(), command)
  16. def check(self, data):
  17. if data.is_command and data.command in ["hash", "encrypt", "decrypt"]:
  18. return True
  19. return False
  20. def process(self, data):
  21. if not data.args:
  22. self.connection.reply(data, "what do you want me to do?")
  23. return
  24. if data.command == "hash":
  25. algo = data.args[0]
  26. if algo in hashlib.algorithms:
  27. string = ' '.join(data.args[1:])
  28. result = eval("hashlib.{0}(string)".format(algo)).hexdigest()
  29. self.connection.reply(data, result)
  30. else:
  31. self.connection.reply(data, "unknown algorithm: {0}".format(
  32. algo))
  33. else:
  34. self.connection.reply(data, "not implemented yet!")