Compare commits
4 Commits
ce2f416611
...
bf94cc23b4
Author | SHA1 | Date |
---|---|---|
randomuser | bf94cc23b4 | |
randomuser | 75f653f1c3 | |
randomuser | 409129ea32 | |
randomuser | 1af43d6960 |
|
@ -0,0 +1,3 @@
|
|||
__pycache__/
|
||||
duckdb
|
||||
chandb
|
|
@ -0,0 +1,24 @@
|
|||
class ChannelDB:
|
||||
def __init__(self, location=None):
|
||||
self.channels = []
|
||||
if not location == None:
|
||||
self.read(location)
|
||||
|
||||
def read(self, location):
|
||||
fd = open(location, "r")
|
||||
[self.channels.append(i.rstrip()) for i in fd.readlines()]
|
||||
fd.close()
|
||||
|
||||
def add(self, channel):
|
||||
self.channels.append(channel)
|
||||
|
||||
def remove(self, channel):
|
||||
self.channels.remove(channel)
|
||||
|
||||
def list(self):
|
||||
return self.channels
|
||||
|
||||
def write(self, location):
|
||||
fd = open(location, "w")
|
||||
[fd.write(i + "\n") for i in self.channels]
|
||||
fd.close()
|
16
main.py
16
main.py
|
@ -6,6 +6,8 @@ from db import DuckDB
|
|||
from db import DuckEvent
|
||||
from db import DuckStats
|
||||
|
||||
from channels import ChannelDB
|
||||
|
||||
from irctokens import build, Line
|
||||
from ircrobots import Bot as BaseBot
|
||||
from ircrobots import Server as BaseServer
|
||||
|
@ -57,6 +59,7 @@ class Server(BaseServer, DuckLogic):
|
|||
duckactivetime = 0
|
||||
lastduck = 0
|
||||
db = "duckdb"
|
||||
chandb = "chandb"
|
||||
|
||||
async def msg(self, chan, msg, usr=None):
|
||||
if usr != None:
|
||||
|
@ -69,10 +72,10 @@ class Server(BaseServer, DuckLogic):
|
|||
async def line_read(self, line: Line):
|
||||
print(f"{self.name} < {line.format()}")
|
||||
if line.command == "001":
|
||||
await self.send(build("JOIN", ["#testchannel"]))
|
||||
chans = ChannelDB(self.chandb)
|
||||
for i in chans.list():
|
||||
await self.send(build("JOIN", [i]))
|
||||
elif line.command == "PRIVMSG":
|
||||
print(line.params)
|
||||
print(line.hostmask.nickname)
|
||||
if line.params[1][0] == '%':
|
||||
cmd = line.params[1].split(' ')[0][1:]
|
||||
chan = line.params[0]
|
||||
|
@ -94,7 +97,14 @@ class Server(BaseServer, DuckLogic):
|
|||
self.messages += 1
|
||||
await self.duck_test()
|
||||
elif line.command == "INVITE":
|
||||
chans = ChannelDB(self.chandb)
|
||||
await self.send(build("JOIN", [line.params[1]]))
|
||||
chans.add(line.params[1])
|
||||
chans.write(self.chandb)
|
||||
elif line.command == "KICK":
|
||||
chans = ChannelDB(self.chandb)
|
||||
chans.remove(line.params[0])
|
||||
chans.write(self.chandb)
|
||||
|
||||
async def line_send(self, line: Line):
|
||||
print(f"{self.name} > {line.format()}")
|
||||
|
|
Loading…
Reference in New Issue