Skip to content

Commit

Permalink
save privileged list periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Sep 18, 2017
1 parent 18dea30 commit 8ff765c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Source/Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, bot_name, client, commands, room_ids, background_tasks=[], bo
self.github_link = github_link
self.background_task_manager = BackgroundTaskManager(background_tasks)
self.chatcommunicate = Chatcommunicate(bot_name, CommandManager(commands, self.rooms))
self.save_directory = os.path.expanduser("~") + "." + self.name.lower()
self.save_directory = os.path.expanduser("~") + "/" + "." + self.name.lower() + "/"

def add_background_task(self, background_task, interval=30, restart=True):
self.background_task_manager.add_background_task(background_task)
Expand All @@ -41,6 +41,9 @@ def add_essential_background_tasks(self, restart=True):
self.add_background_task(BackgroundTask(self.chatcommunicate.command_manager.cleanup_finished_commands, interval=3))
self.add_background_task(BackgroundTask(self.shutdown_check, interval=5))

for each_room in self.rooms:
self.add_background_task(BackgroundTask(each_room.save_privileged_users))

self.background_task_manager.restart_tasks()

def join_rooms(self, watch_callback):
Expand All @@ -65,8 +68,13 @@ def add_privilege_type(self, privilege_level, privilege_name):
for each_room in self.rooms:
each_room.add_privilege_type(privilege_level, privilege_name)

def load_privileged_user_list(self):
for each_room in self.rooms:
each_room.load_privileged_users()

def start_bot(self):
self.join_rooms(self.chatcommunicate.handle_message)
self.load_privileged_user_list()
self.watch_rooms()
self.background_task_manager.start_tasks()

Expand Down
19 changes: 19 additions & 0 deletions Source/CommandPrivilegeUser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# CommandPrivilegeUser.py
# Botpy
#
# Created by Ashish Ahuja on 17th September 2017.
#
#

from Command import *

class CommandPrivilegeUser(Command):
def usage():
return ["privilege * *", "addpriv * *"]

def privileges(self):
return 1

def run(self):

6 changes: 3 additions & 3 deletions Source/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

bot = Bot.Bot("sock", client, commands, [123602])

bot.add_essential_background_tasks()

bot.start_bot()

bot.add_essential_background_tasks()

bot.add_privilege_type(1, "owner")

bot.rooms[0].add_privileged_user(4688119, bot.rooms[0].get_privilege_type_by_name("owner"))
#bot.rooms[0].add_privileged_user(4688119, bot.rooms[0].get_privilege_type_by_name("owner"))

0 comments on commit 8ff765c

Please sign in to comment.