Skip to content

Commit ae7e314

Browse files
committed
Started on scheduling
1 parent d3cbd7b commit ae7e314

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from user import User
2-
from models import Command, session, CommandCommand, QuoteCommand, CubeCommand, SocialCommand
2+
from models import Command, session, CommandCommand, QuoteCommand, CubeCommand, SocialCommand, ScheduleCommand
33
from asyncio import async, coroutine
44
from functools import partial
55

@@ -46,6 +46,7 @@ def message_handler(self, data):
4646
"quote": QuoteCommand,
4747
"cube": CubeCommand,
4848
"social": SocialCommand,
49+
"schedule": ScheduleCommand,
4950
}
5051
if args[0][1:] in commands:
5152
yield from self.send_message(

models.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from datetime import datetime
77
from re import sub, findall
88
from random import randrange
9+
from schedule import Schedule
910

1011
from user import User
1112

@@ -176,6 +177,22 @@ def __call__(self, args, data=None):
176177
return "No social services were found on the streamer's profile."
177178

178179

180+
class ScheduleCommand(Command):
181+
def __call__(self, args, data=None):
182+
action = args[1]
183+
interval = args[2]
184+
text = args[3]
185+
186+
if action is "add":
187+
time = interval[:-1]
188+
modifer = interval[-1:]
189+
190+
191+
elif action is "remove":
192+
pass
193+
else:
194+
pass
195+
179196
# #### TO BE REDONE IN USERS MODEL #### #
180197

181198

@@ -199,6 +216,7 @@ def add_points(self, username, amount):
199216
amount=amount
200217
)
201218
session.add(c)
219+
session.commit()
202220
else:
203221
# Todo add the user.
204222
pass
@@ -239,3 +257,12 @@ def reset_points(self, username):
239257
# TODO: Throw an error and tell the user that sent this bad things
240258
pass
241259
session.commit()
260+
261+
262+
class Schedule(Base):
263+
__tablename__ = "scheduled"
264+
265+
id = Column(Integer, unique=True, primary_key=True)
266+
text = Column(String)
267+
interval = Column(Integer)
268+
last_ran = Column(DateTime)

schedule.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
from models import Scheduled
3+
from sqlalchemy.orm import Session
4+
5+
from time import datetime
6+
7+
from asyncio import coroutine, get_event_loop
8+
9+
10+
class Schedule:
11+
12+
loop = get_event_loop()
13+
14+
def add(self, text, interval):
15+
session = Session()
16+
17+
query = session.query(Scheduled.Base).first()
18+
19+
if query:
20+
c = Scheduled(
21+
text=text,
22+
interval=interval,
23+
last_ran=datetime.utcnow()
24+
)
25+
26+
session.add(c)
27+
session.flush()
28+
session.commit()
29+
else:
30+
raise Exception("WHAT ARE YOU DOING?!")
31+
32+
def remove(self, id):
33+
session = Session()
34+
query = session.query(Scheduled.Base).filter_by(id=id).first()
35+
36+
if query:
37+
query.delete()
38+
session.commit()
39+
else:
40+
raise Exception("That shouldn't have happened.")
41+
42+
@coroutine
43+
def schedule(self, id, interval):
44+
session = Session()
45+
cur_time = 0
46+
47+
query = session.query(Scheduled.Base).filter_by(id=id).first()
48+
49+
if query:
50+
pass
51+
else:
52+
raise Exception("Someting bad happened.")

0 commit comments

Comments
 (0)