0rx

cmd_loop

0rx
Sep 21st, 2015
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.28 KB | None | 0 0
  1. import time
  2. import sys
  3. import random
  4. import imp
  5. import math
  6. import threading
  7. import json
  8. import re
  9. import urllib
  10. import os
  11. import urllib
  12. import codecs
  13. import datetime
  14.  
  15. from xml.etree import cElementTree as ET
  16.  
  17. if sys.version_info[0] > 2:
  18.     import urllib.request as urlreq
  19. else:
  20.     import urllib2 as urlreq
  21.  
  22. ##Variables##
  23. name  = ''
  24. timeout = 0
  25.  
  26. ##Funcs##
  27. def tformat(args):
  28.          minute = 60
  29.          hour   = minute * 60
  30.          day    = hour * 24
  31.          days =  int(args / day)
  32.          hours = int((args % day) / hour)
  33.          minutes = int((args % hour) / minute)
  34.          seconds = int(args % minute)
  35.          string = ""
  36.          if days > 0:
  37.            string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  38.          if len(string) > 0 or hours > 0:
  39.            string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  40.          if len(string) > 0 or minutes > 0:
  41.            string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" ) + ", "
  42.          string += str(seconds) + " " + (seconds == 1 and "second" or "seconds")
  43.          return (string)
  44.  
  45. def timer():
  46.     global timeout
  47.     while timeout > 0:
  48.           if time.time() > timeout:
  49.               print("Timer is up! DRIIING!!! DRIIING!!! DRIIING!!!")
  50.               timeout = 0
  51.  
  52.  
  53. def kick():
  54.     while True:
  55.         try:
  56.             global name
  57.             global timeout
  58.             term = input("Node: ")
  59.             if term == "hi":
  60.                 print("Hi there !! :D")
  61.             if "fuck" in term.lower():
  62.                 print("Yesssshhhh t['~']_, "+term)
  63.             if term.lower() in name and not term.lower() == "":
  64.                   print("Nan desu ka ?")
  65.             if term[0] == "!":
  66.                 data = term[1:].split(" ", 1)
  67.                 if len(data) > 1:
  68.                     node, args =  data[0], data[1]
  69.                 else:
  70.                     node, args = data[0], ""
  71.  
  72.                 ##Core Node##
  73.                 if node == "eval" or node == "ev":
  74.                     ret = repr(eval(args))
  75.                     print(ret)
  76.  
  77.                 if node == "kill":
  78.                     print("Bye bye master :)")
  79.                     return
  80.                 ##Core Node end##
  81.  
  82.                 ##Simple Nodes##
  83.                 if node == "setname":
  84.                     name = args
  85.                     print("changed to "+args)
  86.  
  87.                 if node == "name":
  88.                     if " " in name:
  89.                         tname = name.split(" ", 1)
  90.                         output = random.choice(["Given "+tname[0].title()+" as my last name, and "+tname[1].title()+" be my first name.  Yoroshiku onegaishimasu *Bows down*", ""+tname[0].title()+" be my last name, and given "+tname[1].title()+" as my first name. Yoroshiku onegaishimasu *Bows down*"])
  91.                         print(output)
  92.                     else:
  93.                         print("Atashi no namae wa "+name.title()+" desu. Yoroshiku ne ;)")
  94.  
  95.                 if node == "say":
  96.                     if args == "":
  97.                         print("*Silent*")
  98.                     else:
  99.                         print(args)
  100.                        
  101.                 if node == "rsay":
  102.                     if args == "":
  103.                         print("what should I say"[::-1])
  104.                     else:
  105.                         print(args[::-1])
  106.                 ##Simple Nodes end##
  107.  
  108.                 ##Basic Nodes##
  109.                 if node == "timeset" and len(args) > 1:
  110.                    
  111.                     sec = 0
  112.                     mnt = 0
  113.                     hr  = 0
  114.                    
  115.                     if "s" in args:
  116.                       ss  = args.split("s", 1)
  117.                       sec = int(ss[1].split(" ", 1)[0])
  118.                     elif "m" in args:
  119.                       mm  = args.split("m", 1)
  120.                       mnt = int(mm[1].split(" ", 1)[0])
  121.                     elif "h" in args:
  122.                       h  = args.split("h", 1)
  123.                       hr = int(h[1].split(" ", 1)[0])
  124.                     mnt_sec = mnt * 60
  125.                     hr_sec = hr * 3600
  126.                     args = sec + hr_sec + mnt_sec
  127.                     timeout = time.time() + args
  128.                     string = tformat(args)
  129.                     stime = threading.Thread(target=timer)
  130.                     stime.daemon = True
  131.                     stime.start()
  132.                     print("Timer set is set to ring in: "+string)
  133.  
  134.                
  135.                 if node == "timeleft":
  136.                     if timeout > 0:
  137.                         stf = timeout - time.time()
  138.                         string = tformat(stf)
  139.                         print(string+" left.")
  140.                     else:
  141.                         print("No timer has been set")
  142.                    
  143.                 ##Basic Nodes end##
  144.  
  145.                 ##Complicated Nodes##
  146.  
  147.  
  148.         except KeyboardInterrupt:
  149.             print("I can't live any longer master D:  *commits suicide*")
  150.             break
  151.  
  152.         except Exception as e:
  153.             et, ev, tb = sys.exc_info()
  154.             lineno = tb.tb_lineno
  155.             fn = tb.tb_frame.f_code.co_filename
  156.             print("[Expectation Failed] %s Line %i - %s"% (fn, lineno, str(e)))
  157.  
  158.  
  159. if __name__ == "__main__":
  160.     kick()
Advertisement
Add Comment
Please, Sign In to add comment