-
Notifications
You must be signed in to change notification settings - Fork 0
/
channelfunctions.py
33 lines (27 loc) · 1.07 KB
/
channelfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask import Flask, session
import datetime
class Channel():
def __init__(self, channelname, channels):
self.channelname = channelname
self.channels = channels
def NewChannel(self, username, usernames): #setchannel
if self.channelname in self.channels:
return None
self.channels[self.channelname] = {
'createdBy': username,
'timeCreated': datetime.datetime.now(),
'messages': []
}
usernames[username]['channels'].append(self.channelname)
session['channelname'] = self.channelname
return self.channelname
def getChannel(self):
if self.channelname in self.channels:
session['channelname'] = self.channelname
return session.get('channelname')
return None
def joinChannel(self, username, usernames):
if self.channelname in usernames[username]['channels']:
return None
usernames[username]['channels'].append(self.channelname)
return self.channelname