dickserv- irc bot with many useful commands |
git clone git://git.acid.vegas/dickserv.git |
Log | Files | Refs | Archive | README | LICENSE |
functions.py (1255B)
1 #!/usr/bin/env python 2 # DickServ IRC Bot - Developed by acidvegas in Python (https://acid.vegas/dickserv) 3 # functions.py 4 5 import datetime 6 import random 7 import re 8 import time 9 10 def between(source, start, stop): 11 data = re.compile(start + '(.*?)' + stop, re.IGNORECASE|re.MULTILINE).search(source) 12 if data: 13 return data.group(1) 14 else: 15 return False 16 17 def current_date(): 18 return time.strftime('%A, %B %d, %Y - %I:%M %p') 19 20 def floatint(data): 21 if data.isdigit(): 22 return int(data) 23 else: 24 return float(data) 25 26 def get_date(): 27 return datetime.date.today().strftime('%m/%d/%Y') 28 29 def get_datetime(data): 30 return datetime.datetime.strptime(data, '%m/%d/%Y') 31 32 def luck(odds): 33 if random_int(1,odds) == 1: 34 return True 35 else: 36 return False 37 38 def random_int(min, max): 39 return random.randint(min, max) 40 41 def timespan(date): 42 delta = datetime.date(get_date()) - datetime.date(get_datetime(date)) 43 return delta.days 44 45 def trim(data, max_length): 46 if len(data) > max_length: 47 return data[:max_length] + '...' 48 else: 49 return data 50 51 def uptime(start_time): 52 uptime = datetime.datetime(1,1,1) + datetime.timedelta(seconds=time.time() - start_time) 53 return f'{uptime.day-1} Days, {uptime.hour} Hours, {uptime.minute} Minutes, {uptime.second} Seconds'