LICENSE updated, mirrors updated, minor tweaks

This commit is contained in:
Dionysus 2024-01-20 17:53:26 -05:00
parent bafe01a091
commit 3ffff551db
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
4 changed files with 16 additions and 4 deletions

View File

@ -1,6 +1,6 @@
ISC License ISC License
Copyright (c) 2023, acidvegas <acid.vegas@acid.vegas> Copyright (c) 2024, acidvegas <acid.vegas@acid.vegas>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above

View File

@ -1,5 +1,5 @@
## Information ## Information
This is a basic skeleton for building your own bots for Internet Relay Chat usage. It is asyncronous, can log to file, handle basic I/O, flood control, etc. This is a basic skeleton for building your own bots for Internet Relay Chat *(IRC)* usage. It is asyncronous, can log to file, handle basic I/O, flood control, etc.
A skeleton in Python & Golang *(beta)* are in this repository. A skeleton in Python & Golang *(beta)* are in this repository.
@ -14,5 +14,4 @@ Join **#dev** on **irc.supernets.org** for help building IRC bots frm scratch!
- **RFC7194** - [Default Port for Internet Relay Chat (IRC) via TLS/SSL](https://raw.githubusercontent.com/internet-relay-chat/archive/master/rfc/rfc7194.txt) - **RFC7194** - [Default Port for Internet Relay Chat (IRC) via TLS/SSL](https://raw.githubusercontent.com/internet-relay-chat/archive/master/rfc/rfc7194.txt)
- [Numerics & Events](https://raw.githubusercontent.com/internet-relay-chat/archive/master/numerics.txt) - [Numerics & Events](https://raw.githubusercontent.com/internet-relay-chat/archive/master/numerics.txt)
###### Mirrors ###### Mirrors for this repository: [acid.vegas](https://git.acid.vegas/skeleton) • [SuperNETs](https://git.supernets.org/acidvegas/skeleton) • [GitHub](https://github.com/acidvegas/skeleton) • [GitLab](https://gitlab.com/acidvegas/skeleton) • [Codeberg](https://codeberg.org/acidvegas/skeleton)
[acid.vegas](https://git.acid.vegas/skeleton) • [GitHub](https://github.com/acidvegas/skeleton) • [GitLab](https://gitlab.com/acidvegas/skeleton) • [SuperNETs](https://git.supernets.org/acidvegas/skeleton)

View File

@ -34,6 +34,7 @@ pink = '13'
grey = '14' grey = '14'
light_grey = '15' light_grey = '15'
def color(msg: str, foreground: str, background: str = None) -> str: def color(msg: str, foreground: str, background: str = None) -> str:
''' '''
Color a string with the specified foreground and background colors. Color a string with the specified foreground and background colors.
@ -44,6 +45,7 @@ def color(msg: str, foreground: str, background: str = None) -> str:
''' '''
return f'\x03{foreground},{background}{msg}{reset}' if background else f'\x03{foreground}{msg}{reset}' return f'\x03{foreground},{background}{msg}{reset}' if background else f'\x03{foreground}{msg}{reset}'
def ssl_ctx(verify: bool = False, cert_path: str = None, cert_pass: str = None) -> ssl.SSLContext: def ssl_ctx(verify: bool = False, cert_path: str = None, cert_pass: str = None) -> ssl.SSLContext:
''' '''
Create a SSL context for the connection. Create a SSL context for the connection.
@ -57,6 +59,7 @@ def ssl_ctx(verify: bool = False, cert_path: str = None, cert_pass: str = None)
ctx.load_cert_chain(cert_path) if not cert_pass else ctx.load_cert_chain(cert_path, cert_pass) ctx.load_cert_chain(cert_path) if not cert_pass else ctx.load_cert_chain(cert_path, cert_pass)
return ctx return ctx
class Bot(): class Bot():
def __init__(self): def __init__(self):
self.nickname = 'skeleton' self.nickname = 'skeleton'
@ -66,6 +69,7 @@ class Bot():
self.writer = None self.writer = None
self.last = time.time() self.last = time.time()
async def action(self, chan: str, msg: str): async def action(self, chan: str, msg: str):
''' '''
Send an ACTION to the IRC server. Send an ACTION to the IRC server.
@ -75,6 +79,7 @@ class Bot():
''' '''
await self.sendmsg(chan, f'\x01ACTION {msg}\x01') await self.sendmsg(chan, f'\x01ACTION {msg}\x01')
async def raw(self, data: str): async def raw(self, data: str):
''' '''
Send raw data to the IRC server. Send raw data to the IRC server.
@ -83,6 +88,7 @@ class Bot():
''' '''
self.writer.write(data[:510].encode('utf-8') + b'\r\n') self.writer.write(data[:510].encode('utf-8') + b'\r\n')
async def sendmsg(self, target: str, msg: str): async def sendmsg(self, target: str, msg: str):
''' '''
Send a PRIVMSG to the IRC server. Send a PRIVMSG to the IRC server.
@ -92,6 +98,7 @@ class Bot():
''' '''
await self.raw(f'PRIVMSG {target} :{msg}') await self.raw(f'PRIVMSG {target} :{msg}')
async def connect(self): async def connect(self):
'''Connect to the IRC server.''' '''Connect to the IRC server.'''
while True: while True:
@ -117,6 +124,7 @@ class Bot():
finally: finally:
await asyncio.sleep(30) # Wait 30 seconds before reconnecting await asyncio.sleep(30) # Wait 30 seconds before reconnecting
async def eventPRIVMSG(self, data: str): async def eventPRIVMSG(self, data: str):
''' '''
Handle the PRIVMSG event. Handle the PRIVMSG event.
@ -152,6 +160,7 @@ class Bot():
await self.sendmsg(target, option) await self.sendmsg(target, option)
self.last = time.time() # Update the last command time if it starts with ! character to prevent command flooding self.last = time.time() # Update the last command time if it starts with ! character to prevent command flooding
async def handle(self, data: str): async def handle(self, data: str):
''' '''
Handle the data received from the IRC server. Handle the data received from the IRC server.
@ -212,6 +221,8 @@ def setup_logger(log_filename: str, to_file: bool = False):
else: else:
logging.basicConfig(level=logging.NOTSET, handlers=(sh,)) logging.basicConfig(level=logging.NOTSET, handlers=(sh,))
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Connect to an IRC server.") # The arguments without -- are required arguments. parser = argparse.ArgumentParser(description="Connect to an IRC server.") # The arguments without -- are required arguments.
parser.add_argument("server", help="The IRC server address.") parser.add_argument("server", help="The IRC server address.")

View File

@ -1,3 +1,5 @@
// irc bot skeleton - developed by acidvegas in golang (https://git.acid.vegas/skeleton)
package main package main
import ( import (