Skip to content

Commit

Permalink
Merge branch 'development' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iogf committed Nov 27, 2020
2 parents 414225f + c4f02f4 commit 39c603b
Show file tree
Hide file tree
Showing 33 changed files with 297 additions and 175 deletions.
171 changes: 168 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,179 @@ pip install -r requirements.txt
pip install ameliabot
~~~

Documentation
=============
Usage
=====

[Wiki](https://github.com/iogf/ameliabot/wiki)

The command below should be issued after the installation.

~~~
amelia --init
~~~

It will create the following dir/files.

~~~
~/.amelia/
ameliarc
~~~

Then edit your **./amelia/ameliarc** file to setup
your networks and channels as well as plugins.

Amelia allows one to set up plugin scheme per network.
Your ameliarc file would look alike the below one:

~~~python
from ameliabot.core import connect
from ameliabot.plugins import load
##############################################################################
import sys

# You can place your plugins at ~/.amelia # To use them inside this file just do.
# import plugin_package_name or import plugin_name

from os.path import expanduser, join
sys.path.append(join(expanduser('~'), '.amelia'))
##############################################################################
# The plugin imports.

from ameliabot.plugins import join
# from ameliabot.plugins import spam
# from ameliabot.plugins import advisor

from ameliabot.plugins import logmsg
from ameliabot.plugins import tell
from ameliabot.plugins import troll
from ameliabot.plugins import calc
from ameliabot.plugins import url_title
from ameliabot.plugins import codebox
from ameliabot.plugins import codenv
from ameliabot.plugins import note
from ameliabot.plugins import pipe
from ameliabot.plugins import seen
from ameliabot.plugins import keep_alive
from ameliabot.plugins import ircadm
from ameliabot.plugins import help
from ameliabot.plugins.quote import quote
# from ameliabot.plugins import booklist
from ameliabot.plugins import dcc_send
from ameliabot.plugins import dcc_get
from ameliabot.plugins import translator
from ameliabot.plugins import polyglot
from ameliabot.plugins import lichess
from ameliabot.plugins import antispam
from ameliabot.plugins import latex
from ameliabot.plugins import mathb


##############################################################################
# Initialize a connection to the irc server

freenode = connect('irc.freenode.org', 6667,
'amelia', 'fuinho fuinho fuinho :fuinho',
'PRIVMSG nickserv :IDENTIFY nick_passwd',
'fooobarr', ['#not-math', '##math-offtopic', '#vy'])

# Install plugins in the connection.
# load(freenode, join)
# load(freenode, spam, db=['alpha', 'beta'])
# load(freenode, advisor, questions='questions', suggestions='suggestions')

load(freenode, tell)
load(freenode, troll, 'aeiuh', 8, 15)
load(freenode, calc, '4WERXG-VAGETKREGX')
load(freenode, url_title)
load(freenode, codebox)
load(freenode, codenv, 'python3', '=py', '=end')
load(freenode, codenv , 'c', '=c', '=end')
load(freenode, codenv, 'c++', '=c++', '=end')
load(freenode, codenv, 'd', '=d', '=end')
load(freenode, codenv, 'lua', '=lua', '=end')
load(freenode, codenv, 'ocaml', '=ocaml', '=end')
load(freenode, codenv, 'php', '=php', '=end')
load(freenode, codenv, 'perl', '=perl', '=end')
load(freenode, codenv, 'ruby', '=ruby', '=end')
load(freenode, codenv, 'scheme', '=scheme', '=end')
load(freenode, codenv, 'tcl', '=tcl', '=end')
load(freenode, note)
load(freenode, pipe)
load(freenode, seen)
load(freenode, keep_alive)
load(freenode, ircadm)
load(freenode, help)
load(freenode, quote)
load(freenode, translator)
load(freenode, polyglot)
load(freenode, lichess)
load(freenode, antispam, n_lines=5, n_secs=5,
cmd='kick {chan} {nick} :Amelia rocks!')
load(freenode, latex)
load(freenode, mathb)

# load(freenode, dcc_send, '/home/tau/Downloads')
# load(freenode, dcc_get, '/home/tau/Downloads')

##############################################################################
# Initialize another connection...

# virtualife = connect('irc.virtualife.com.br', 6667,
# 'ameliabot',
# 'untwistedbot euler euler :Ameliabot',
# 'NickServ IDENTIFY nick_passwd',
# 'bot_passwd', ['#brasil'])

# load(virtualife, quick_search)
# load(virtualife, tell)
# load(virtualife, troll, 'aeiuh', 8, 15)
# load(virtualife, calc, '4WERXG-VAGETKREGX')
# load(virtualife, url_title)
# load(virtualife, codebox)
~~~


Once you have set your plugins, channels and networks
just issue:

~~~
amelia --run
~~~

## Command Format

The command format scheme follows the following scheme.

~~~
@command arg1 arg2 ... arg_n 'argument with spaces' "argument with spaces"
~~~

## Command Help

The command below lists all loaded plugins for a given network.

~~~
@plugins
~~~

In order to get help for a given plugin then issue.

~~~
@doc plugin_name
~~~

## Credentials

Some plugins demand a given user to be authenticated.

The command to authenticate with amelia is as follow. Such a command has
to be issued as a private message.

~~~
@login password
~~~

Once the user is logged, amelia will keep the user's host in memory. Whenever an user
issues a command that demands authentication, amelia will check the user host.


3 changes: 1 addition & 2 deletions ameliabot/adm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from untwisted.network import xmap
from quickirc import send_msg
from ameliabot.cmd import command

known = set()

def install(server):
xmap(server, 'PMSG', login)
server.add_map('PMSG', login)

@command('@login password')
def login(server, nick, user, host, target, msg, password):
Expand Down
2 changes: 1 addition & 1 deletion ameliabot/ameliarc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ load(freenode, troll, 'aeiuh', 8, 15)
load(freenode, calc, '4WERXG-VAGETKREGX')
load(freenode, url_title)
load(freenode, codebox)
load(freenode, codenv, 'python', '=py', '=end')
load(freenode, codenv, 'python3', '=py', '=end')
load(freenode, codenv , 'c', '=c', '=end')
load(freenode, codenv, 'c++', '=c++', '=end')
load(freenode, codenv, 'd', '=d', '=end')
Expand Down
31 changes: 17 additions & 14 deletions ameliabot/core.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from untwisted.network import Spin, xmap
from untwisted.iostd import Client, Stdin, Stdout, CLOSE, CONNECT_ERR, CONNECT
from socket import socket, AF_INET, SOCK_STREAM, gethostbyname
from untwisted.network import SuperSocket
from untwisted.client import Client, lose
from untwisted.sock_writer import SockWriter
from untwisted.event import CLOSE, CONNECT_ERR, CONNECT
from untwisted.sock_reader import SockReader
from untwisted.splits import Terminator, logcon
from quickirc import Irc, CTCP, Misc, send_cmd
from socket import socket, AF_INET, SOCK_STREAM, socket, gethostbyname
from ameliabot import adm
from untwisted.tools import coroutine

def connect(servaddr, port, nick, user, nick_passwd, adm_passwd, chan_list):
sock = socket(AF_INET, SOCK_STREAM)
ip = gethostbyname(servaddr)
server = Spin(sock)
server = SuperSocket(sock)
Client(server)

def auto_join(server, *args):
Expand All @@ -31,8 +34,8 @@ def update_nick(server, nick_x, user, host, nick_y):
server.nick = nick_y

def handle_connect(server):
Stdin(server)
Stdout(server)
SockWriter(server)
SockReader(server)
Terminator(server)

Irc(server)
Expand All @@ -41,15 +44,15 @@ def handle_connect(server):
Misc(server)
adm.install(server)

xmap(server, 'PING', lambda server, prefix, servaddr:
send_cmd(server, 'PONG :%s' % servaddr))
server.add_map('PING', lambda server, prefix, servaddr:
send_cmd(server, 'PONG :%s' % servaddr))

xmap(server, CLOSE, lambda server, err: lose(server))
server.add_map(CLOSE, lambda server, err: lose(server))
logcon(server)

xmap(server, '376', auto_join)
xmap(server, '376', get_myaddr)
xmap(server, 'NICK', update_nick)
server.add_map('376', auto_join)
server.add_map('376', get_myaddr)
server.add_map('NICK', update_nick)

server.servaddr = servaddr
server.port = port
Expand All @@ -62,8 +65,8 @@ def handle_connect(server):
send_cmd(server, 'NICK %s' % nick)
send_cmd(server, 'USER %s' % user)

xmap(server, CONNECT, handle_connect)
xmap(server, CONNECT_ERR, lambda server, err: lose(server))
server.add_map(CONNECT, handle_connect)
server.add_map(CONNECT_ERR, lambda server, err: lose(server))

server.connect_ex((ip, port))
return server
Expand Down
5 changes: 2 additions & 3 deletions ameliabot/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from untwisted.network import xmap
from untwisted.iostd import CONNECT
from untwisted.event import CONNECT

def load(con, plugin, *args, **kwargs):
xmap(con, CONNECT, lambda con: plugin.install(
con.add_map(CONNECT, lambda con: plugin.install(
con, *args, **kwargs))


Expand Down
5 changes: 2 additions & 3 deletions ameliabot/plugins/advisor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from time import asctime
from random import choice, randint
from untwisted.network import xmap
from quickirc import send_msg
from untwisted.timer import Timer
import os
Expand All @@ -17,8 +16,8 @@ def __init__(self, server, questions, suggestions, pmed_file='pmed',
self.pmed_file = pmed_file
self.blacklist = self.load(blacklist_file)
self.blacklist_file = blacklist_file
xmap(server, 'JOIN', self.send_question)
xmap(server, 'PMSG', self.check_answer)
server.add_map('JOIN', self.send_question)
server.add_map('PMSG', self.check_answer)

def load(self, filename):
with open(filename, 'a+') as fd:
Expand Down
3 changes: 1 addition & 2 deletions ameliabot/plugins/antispam.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def PLUGIN_SCHEME(server):
"""

from quickirc import send_cmd, send_msg
from untwisted.network import xmap
from ameliabot.cmd import regcmd
import time

Expand All @@ -25,7 +24,7 @@ def __init__(self, server, n_lines, n_secs, cmd):
cmd = 'kick {chan} {nick} :Amelia rocks!'
cmd = 'chanserv akick {chan} add *!*@{host} : get out!
"""
xmap(server, 'CMSG', self.watcher)
server.add_map('CMSG', self.watcher)
self.data = {}
self.n_lines = n_lines
self.n_secs = n_secs
Expand Down
17 changes: 3 additions & 14 deletions ameliabot/plugins/booklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"""

import libpad
from untwisted.network import xmap
from quickirc import send_msg
from ameliabot.cmd import command
import os
Expand All @@ -24,21 +22,12 @@ def __init__(self, server, folder):
"""

self.folder = folder
xmap(server, 'CMSG', self.list_folder)
server.add_map('CMSG', self.list_folder)

@command('@dcc-list')
def list_folder(self, server, nick, user, host, target, msg):
"""
"""
content = '\n'.join(os.listdir(self.folder))

url, _ = libpad.sandbox(content, '')
send_msg(server, target, url)








send_msg(server, target, content)

3 changes: 1 addition & 2 deletions ameliabot/plugins/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import wolframalpha

from quickirc import send_msg
from untwisted.network import xmap
from ameliabot.cmd import regcmd
from ameliabot.tools import send_lines

class Calculate(object):
def __init__(self, server, appid):
self.client = wolframalpha.Client(appid)
xmap(server, 'CMSG', self.calculate)
server.add_map('CMSG', self.calculate)

@regcmd('@calc (?P<exp>.+)$')
def calculate(self, server, nick, user, host, target, msg, exp):
Expand Down
Loading

0 comments on commit 39c603b

Please sign in to comment.