List of commits:
Subject Hash Author Date (UTC)
Renamed Discord client subclass. Added auto reconnect. d459050a47143f7c8ad03617c31b7aaac8945a0d Detche 2016-12-13 08:39:12
Added license e6b536833829fc4bbe79db91151e3fdd97cef571 Detche 2016-12-03 11:45:16
Added python version as dependency 7eba5cb00dc648b3f2cfcf464073a9513c44774b Detche 2016-12-03 11:42:32
Changed to a valid user id for testing purposes. 6e3f897c46e9cd410b9744b2b46d8a0b81e05fd8 Detche 2016-12-03 11:39:42
Added set accessor for users. Added change_affinity() 62ffb2301d0474abcf0afbca4b9bb4706821dd46 Detche 2016-12-03 11:38:00
Added date and time on log entries 7ea1d025aa1ce07d42e3c9fe2065a1d1b12f0679 Detche 2016-12-03 11:35:29
Updated examples b7dd5285bf52883a01339df401091749df97f856 Detche 2016-12-03 11:34:31
Fixed trigger change method 69251e3588123264763e72e0d75e24f6efabac21 Detche 2016-12-01 15:36:51
Reverted to Python 3.4 asyncio syntax. 43f7209ba91a14f6e6ac1f9727542c2184660399 Detche 2016-12-01 15:05:40
Fixed reaction on discord reactions. 8ee16b5e61d096d1905643cec4da05e7714ed75c Detche 2016-11-29 16:41:56
Fixed log error on leave(). cde179a63badbfdfd17a345886214e1d2b0a1e54 Detche 2016-11-29 15:44:53
Bot now prints in a log file if given at initialization e13bd3dbb86d1bb6f072f751412e89d444d870f3 Detche 2016-11-29 15:38:18
Updated example. e95d1599676ae10b950b2c069e666060005627cf Detche 2016-11-13 19:52:41
Added scheduler to task core. Modified comm for new event. ed51d5d18684dabdb17675294727ad5e8b8af454 Detche 2016-11-13 19:44:05
Started adding possibility to save in database. cf28a7731335cd1ffd2ebd03cc2e890c25e1c64b Detche 2016-11-13 19:43:21
Changed db interface and users/groups models. d0fdf8873a107c44d6acbef5cbffc869461d9aab Detche 2016-11-03 15:22:10
Changed UserId from element to attribute. 5407592cba9e7488519e069927a8ffb9ed32fdf6 Detche 2016-11-02 15:02:30
Added tasks system. 13bbf9857a0a61d5e2b0fd9483f5efd235cbd4f2 Detche 2016-11-02 14:58:20
Modified Knowledge process. Fixed indent 28e52095a297cbb0e6b9b6d799bb80ebe52828c1 Detche 2016-10-23 12:11:30
Updated README 8e298151286ec3cb4df29633aaca90fc871f2e80 Detche 2016-10-23 10:10:45
Commit d459050a47143f7c8ad03617c31b7aaac8945a0d - Renamed Discord client subclass. Added auto reconnect.
Author: Detche
Author date (UTC): 2016-12-13 08:39
Committer name: Detche
Committer date (UTC): 2016-12-13 08:39
Parent(s): e6b536833829fc4bbe79db91151e3fdd97cef571
Signing key:
Tree: 9bb508c7153ef52c2f1dbd930e780831d2aed259
File Lines added Lines deleted
botly/bot.py 19 7
botly/client.py 3 3
botly/task.py 6 4
File botly/bot.py changed (mode: 100644) (index ac1883e..dd79f54)
... ... import discord
9 9 from botly.db import Db from botly.db import Db
10 10 from botly.settings import Settings from botly.settings import Settings
11 11 from botly.knowledge import Knowledge from botly.knowledge import Knowledge
12 from botly.comm import Comm
12 from botly.client import Client
13 13 from botly.task import load_tasks from botly.task import load_tasks
14 14 from botly.reaction import load_reactions from botly.reaction import load_reactions
15 15 from botly.behaviour import Behaviour from botly.behaviour import Behaviour
 
... ... class Bot:
22 22 """Initialization loads database, reactions and tasks from drive.""" """Initialization loads database, reactions and tasks from drive."""
23 23 self.me = None self.me = None
24 24 self.server = None self.server = None
25 self.askedToLeave = False
25 26 self.logPath = logFile self.logPath = logFile
26 27
27 28 # Load database and models # Load database and models
 
... ... class Bot:
30 31 self.knowledge = Knowledge() self.knowledge = Knowledge()
31 32
32 33 # Create discord client object for communication and event reception # Create discord client object for communication and event reception
33 self.comm = Comm(self)
34 self.client = Client(self)
35 # alias, as old name may be still in use somwhere
36 self.comm = self.client
34 37
35 38 # Load the bot background tasks # Load the bot background tasks
36 39 for task in load_tasks(self, rootModule + '.tasks'): for task in load_tasks(self, rootModule + '.tasks'):
37 self.comm.loop.create_task(task._run())
40 self.client.loop.create_task(task._run())
38 41
39 42 # Load the bot behaviour (reactions to events) # Load the bot behaviour (reactions to events)
40 43 self.behaviour = Behaviour(load_reactions(self, self.behaviour = Behaviour(load_reactions(self,
 
... ... class Bot:
48 51 """Runs the bot until it is exited. """ """Runs the bot until it is exited. """
49 52 # Listen to Discord's events (blocking call) # Listen to Discord's events (blocking call)
50 53 self.print("Connecting to Discord...") self.print("Connecting to Discord...")
51 self.comm.run()
52 self.print("Botly exited.")
54 self.client.run()
55 if not self.askedToLeave:
56 self.print('Botly exited without being asked to. Will reconnect.')
57 # TODO: This might be incorrect, as perhaps we'd require reloading
58 # the whole robot, as the event loop will be ended and tasks
59 # wouldn't be there anymore. Maybe we should check for
60 # disconnectiong somewhere else.
61 self.live()
62 else:
63 self.print("Botly exited.")
53 64
54 65 def print(self, message, msgtype='INFO'): def print(self, message, msgtype='INFO'):
55 66 dt = datetime.datetime.now() dt = datetime.datetime.now()
 
... ... class Bot:
68 79 @asyncio.coroutine @asyncio.coroutine
69 80 def leave(self): def leave(self):
70 81 """Coroutine that disconnects the robot from Discord.""" """Coroutine that disconnects the robot from Discord."""
71 yield from self.comm.logout()
82 self.askedToLeave = True
83 yield from self.client.logout()
72 84
73 85 @asyncio.coroutine @asyncio.coroutine
74 86 def say(self, channel, message): def say(self, channel, message):
75 87 """Coroutine that send a message to discord.""" """Coroutine that send a message to discord."""
76 yield from self.comm.send_message(channel, message)
88 yield from self.client.send_message(channel, message)
77 89
78 90 def set_bot_info(self, user, server): def set_bot_info(self, user, server):
79 91 """This will be called once the bot is connected to Discord.""" """This will be called once the bot is connected to Discord."""
File botly/client.py renamed from botly/comm.py (similarity 91%) (mode: 100644) (index e1adc16..e65066b)
... ... import asyncio
6 6 import discord import discord
7 7
8 8
9 class Comm(discord.Client):
9 class Client(discord.Client):
10 10 """Inherits from discord.client. Used for communication with server.""" """Inherits from discord.client. Used for communication with server."""
11 11
12 12 def __init__(self, bot): def __init__(self, bot):
13 13 self.bot = bot self.bot = bot
14 super(Comm, self).__init__(max_messages=bot.settings.get_int(
14 super(Client, self).__init__(max_messages=bot.settings.get_int(
15 15 'CacheMaxMessages')) 'CacheMaxMessages'))
16 16
17 17 @asyncio.coroutine @asyncio.coroutine
 
... ... class Comm(discord.Client):
63 63 after=after) after=after)
64 64
65 65 def run(self): def run(self):
66 super(Comm, self).run(self.bot.settings.get_string('DiscordToken'))
66 super(Client, self).run(self.bot.settings.get_string('DiscordToken'))
67 67
68 68
File botly/task.py changed (mode: 100644) (index ca4f4d1..9acf28c)
... ... DAY_FRIDAY = 16
30 30 DAY_SATURDAY = 32 DAY_SATURDAY = 32
31 31 DAY_SUNDAY = 64 DAY_SUNDAY = 64
32 32
33
33 34 class TaskBase: class TaskBase:
34 35 """Base class for bot's background tasks""" """Base class for bot's background tasks"""
35 36
 
... ... class TaskBase:
82 83 self.bot = bot self.bot = bot
83 84 self.knowledge = bot.knowledge self.knowledge = bot.knowledge
84 85 self.settings = bot.settings self.settings = bot.settings
85 self.comm = bot.comm
86 self.client = bot.client
87 self.comm = bot.client # alias because still in use in tasks
86 88
87 89 self.maxDaysLookup=self.settings.get_int('MaximumTaskDaysLookup', '15') self.maxDaysLookup=self.settings.get_int('MaximumTaskDaysLookup', '15')
88 90 self.minimumTimeout = bot.settings.get_int('MinimumTaskTimeout', '10') self.minimumTimeout = bot.settings.get_int('MinimumTaskTimeout', '10')
 
... ... class TaskBase:
99 101 """Will start the task scheduler. Do not overwrite.""" """Will start the task scheduler. Do not overwrite."""
100 102
101 103 # Wait until the bot is ready before running the task # Wait until the bot is ready before running the task
102 yield from self.comm.wait_until_ready()
104 yield from self.client.wait_until_ready()
103 105
104 while not self.comm.is_closed or not self.endTask:
106 while not self.client.is_closed or not self.endTask:
105 107 timeout = self._get_next_timeout() timeout = self._get_next_timeout()
106 108 if timeout is None or timeout == 0: if timeout is None or timeout == 0:
107 109 break break
 
... ... class TaskBase:
111 113 # We'll wait till the task is allowed to run # We'll wait till the task is allowed to run
112 114 yield from asyncio.sleep(timeout) yield from asyncio.sleep(timeout)
113 115 # Was the communication after waiting for the trigger? # Was the communication after waiting for the trigger?
114 if self.comm is None or self.comm.is_closed or self.endTask:
116 if self.client is None or self.client.is_closed or self.endTask:
115 117 break break
116 118 # Execute the task # Execute the task
117 119 yield from self.do() yield from self.do()
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/detche/Botly

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/detche/Botly

Clone this repository using git:
git clone git://git.rocketgit.com/user/detche/Botly

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main