ftoc.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. ##Converts farenheit to celcius##
  3. import sys
  4. from event import Event
  5. if sys.version_info > (3, 0, 0):
  6. try:
  7. from .basemodule import BaseModule
  8. except (ImportError, SystemError):
  9. from modules.basemodule import BaseModule
  10. else:
  11. try:
  12. from basemodule import BaseMOdule
  13. except (ImportError, SystemError):
  14. from modules.basemodule import BaseModule
  15. class Ftoc(BaseModule):
  16. def post_init(self):
  17. ftoc = Event("__.ftoc__")
  18. ftoc.define(msg_definition="^\.ftoc")
  19. ftoc.subscribe(self)
  20. self.cmd = ".ftoc"
  21. self.help = ".ftoc [farenheit]"
  22. self.bot.register_event(ftoc, self)
  23. def handle(self, event):
  24. try:
  25. if event.msg.startswith(".ftoc"):
  26. split_msg = event.msg.split() #Splits the command from the number ['.ftoc', '<some number>']
  27. f_temp = split_msg[1]
  28. f = float(f_temp)
  29. c = (f - 32)*(.5555) #Does math to convert from freedom units to celcius
  30. self.say(event.channel, str(round(c, 1)) + "° C") #Spits it out in the proper channel
  31. except ValueError:
  32. self.say(event.channel, "Enter a number you rube!")
  33. except IndexError:
  34. self.say(event.channel, "Try '.ftoc [farenheit]'")