Free Software Directory:IRC bot

From Free Software Directory
 
Jump to: navigation, search

IMPORTANT NOTE:

There is no mode to ban all bots. Ban exemption can be added with cmode +e. The #fsf ban list is currently empty, you can check it with /mode +b. See https://sopel.chat/appendix/comparison-to-other-bots/ why Sopel is a good choice. --David Hedlund (talk) 14:19, 24 September 2021 (EDT)

The FSD administrator,
[Please specify the "signature" parameter. "signature=--~~~~" to produce a link to your admin profile.]


#fsf objectives

IRC Friday Meeting hourly reminders

Timings and messages

  • Start meeting: The Free Software Directory meeting starts now.
  • Second hour: We're are entering the second hour of the Free Software Directory meeting.
  • Third hour: We're are entering the third hour of the Free Software Directory meeting.
  • Stop meeting: The Free Software Directory meeting stops now.

Approved revisions

"I space out the approvals so the meeting has the illusion of being more active. :)" - Craig

(19:09:18) craigt: [APPROVED] <https://directory.fsf.org/wiki/389-adminutil> [(removed duplicate "accepts crypto donations" entry)]
(19:29:12) craigt: [APPROVED] <https://directory.fsf.org/wiki/389-admin-console> [(removed duplicate "accepts crypto donations" entry)]
(19:51:01) craigt: [APPROVED] <https://directory.fsf.org/wiki/389-admin> [(removed duplicate "accepts crypto donations" entry)]

This can be done with a bot, example:

(19:09:18) fsfbot: [craigt APPROVED] <https://directory.fsf.org/wiki/389-adminutil> [(removed duplicate "accepts crypto donations" entry)]
(19:29:12) fsfbot: [craigt APPROVED] <https://directory.fsf.org/wiki/389-admin-console> [(removed duplicate "accepts crypto donations" entry)]
(19:51:01) fsfbot: [craigt APPROVED] <https://directory.fsf.org/wiki/389-admin> [(removed duplicate "accepts crypto donations" entry)]

Requirements

  • "Constantly running seems a bit much, but having it running during the meeting would be welcome." - craig
  • "Bash and python are equal to me for automation. Beautiful soup is probably the most full featured, but a chain of curl, awk, sed, and grep, can probably do it easily enough." - thomzane

Sopel

Set up the bot

https://git.sr.ht/~noisytoot/fsfbot-sopel/tree/master/item/README.md

#fsf objectives

IRC Friday Meeting hourly reminders

See https://git.sr.ht/~noisytoot/fsfbot-sopel/tree/master/item/fsf-channel.py

Approved revisions

TODO

Eggdrop (replace with Sopel)

Set up the bot

#####################################################################
Before you begin

Register the nick fsfbot on irc.libera.chat before anyone else does it.
https://libera.chat/guides/registration

# Make sure that the bot successfully registered in IRC:
/nickserv info fsfbot

#####################################################################
Background

I could not find a eggdrop.conf file after `sudo apt install eggdrop` in Trisquel 8 even if the manual says that it should be distributed with it:
man eggdrop: "Eggdrop needs a config file to run. For an example, have a look at eggdrop.conf which is distributed with Eggdrop."

So instead I compiled eggdrop and generated the necessarily files including eggdrop.conf.


The steps to use eggdrop provided in this document is intended as a complement to http://www.egghelp.org/setup.htm


#####################################################################
Compiling

Install package dependencies: tcl tcl-dev
Download your desired version from https://ftp.eggheads.org/pub/eggdrop/source/, extract it, and place it where you want it to be, and cd into that directory.

./configure && make config && make
# The default bot installation directory for `make install` is ~/eggdrop/ but you can customize it with `make install DEST=/home/name/botdir`
make install

#####################################################################
Configure the .conf file

make install that we ran in the previous step said: "You MUST ensure that you edit/verify your configuration file.
An example configuration file, eggdrop.conf, is distributed with Eggdrop."

Visit the bot directory (~/eggdrop/ by default).


¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Quick fix

eggdrop_conf_file="fsfbot.conf";
eggdrop_nick="fsfbot";
eggdrop_real_name="FSFBot";
eggdrop_altnick="fsfbot2";
eggdrop_owner="David_Hedlund"; # Use the IRC nick will run the `/msg fsfbot hello` command
eggdrop_port="6183";
eggdrop_server_1="irc.libera.chat";
eggdrop_server_1_password="";
cp -a eggdrop.conf $eggdrop_conf_file # Copy the default conf file (eggdrop.conf) to keep the original file to a new file.
sed -i "s|^#set owner \"MrLame, MrsLame\"|set owner \"$eggdrop_owner\"|" $eggdrop_conf_file
grep "$eggdrop_owner" $eggdrop_conf_file || echo "ERRROR: set owner failed"
sed -i "s|Lamestbot|$eggdrop_nick|g" $eggdrop_conf_file
grep "$eggdrop_nick" $eggdrop_conf_file || echo "ERROR: The nick failed to be replaced in multiple places"
sed -i "s|LamestBot|$eggdrop_real_name|g" $eggdrop_conf_file
grep "$eggdrop_real_name" $eggdrop_conf_file || echo "ERROR: The real name was has not been replaced in multiple places"
sed -i "s|global botnick|putserv \"privmsg nickserv :identify $eggdrop_server_1_password\"\n  global botnick|" $eggdrop_conf_file
grep "$eggdrop_server_1_password" $eggdrop_conf_file || echo "ERROR: privmsg nickserv :identify failed"
sed -i "s|^set altnick \"Llamab?t\"|set altnick \"$eggdrop_altnick\"|" $eggdrop_conf_file
grep "$eggdrop_altnick" $eggdrop_conf_file || echo "ERROR: set altnick failed"
sed -i "s|^#listen 3333 all|listen $eggdrop_port all|" $eggdrop_conf_file
grep "$eggdrop_port" $eggdrop_conf_file || echo "ERROR: listen NUMBER failed"
sed -i "s|^set servers {|set servers {\n  $eggdrop_server_1|" $eggdrop_conf_file
grep "$eggdrop_server_1" $eggdrop_conf_file || echo "ERROR: set servers failed"
# Delete examples
sed -i '/you.need.to.change.this/d' $eggdrop_conf_file
sed -i '/another.example.com/d' $eggdrop_conf_file
sed -i '/2001:db8:618:5c0:263/d' $eggdrop_conf_file
sed -i '/ssl.example.net/d' $eggdrop_conf_file
# When everything has been configured so you can terminate eggdrop from a DCC or Telnet, comment out the `die ` lines -- these are in fact the only lines that need to be changed to be able to run eggdrop, the rest is just configuration.
sed -i "s|^die|#die|" $eggdrop_conf_file
grep "^#die" $eggdrop_conf_file || echo "ERROR: Did not uncomment all die lines"
echo "#####################################################################
# Custom source
" >> $eggdrop_conf_file
echo "source scripts/fsf_channel.tcl" >> $eggdrop_conf_file

#####################################################################
Starting Eggdrop


First, put the fsf_channel.tcl script in ~/eggdrop/scripts/

¤¤¤
If you would like to add other channel announcer in the future just do this (example with libreplanet):

channel="libreplanet";
meeting_title="LibrePlanet";
cron_day="3";
eggdrop_conf_file="~/eggdrop/fsfbot.conf";
cd ~/eggdrop
cd scripts
cp -a fsf_channel.tcl "$channel"_channel.tcl
sed -i "
s|* * 5|* * $cron_day|
s|#fsf|#$channel|
s|fsf_channel|$channel"_channel"|
s|Free Software Directory|$meeting_title|
s|https://directory.fsf.org/wiki/Free_Software_Directory:Participate|https://libreplanet.org/wiki/LibrePlanet:Participate|
" "$channel"_channel.tcl
line="source scripts/libreplanet_channel.tcl"
if ! grep -q "$line" $eggdrop_conf_file; then echo "$line" >> $eggdrop_conf_file && echo "$line" || echo "$line is in $eggdrop_conf_file"; fi

¤¤¤


# from `man eggdrop` for the -m option: "Create  userfile.  If  you don't have a userfile, this will make Eggdrop create one and give owner status to the first person that introduces himself or herself to it. You'll need to do this when you first set up your bot."
./eggdrop -m fsfbot.conf
[...]
STARTING BOT IN USERFILE CREATION MODE.
Telnet to the bot and enter 'NEW' as your nickname.
OR go to IRC and type:  /msg fsfbot hello
This will make the bot recognize you as the the master.
[...]



* Log in to IRC (but not as fsfbot) with the same nick that you added to `set owner` in fsfbot.conf
/msg fsfbot hello
* It will say "(notice) As master you really need to set a password: with /MSG fsfbot pass <your-chosen-password>." Long passwords will be reduced to 15 characters, save the password from the output: `(notice) Password set to: '<your password>'.`
/msg fsfbot pass <some new password>
sudo apt-get install telnet
# Use the port in the .conf file that you modified in `listen 3333 all`. Yo will be prompted to login: nick: <the nick you use used to `/msg fsfbot hello`> Password: <your password>
telnet localhost 6183


# Join a channel. Adding chans in .conf file is deprecated
.+chan #fsf
.+chan #libreplanet

# Evaluate the messages
# .tcl fsf_channel__channel_message__start_meeting * * * * *
# .tcl fsf_channel__channel_message__second_hour * * * * * 
# .tcl fsf_channel__channel_message__third_hour * * * * * 
# .tcl fsf_channel__channel_message__stop_meeting * * * * *

# Initialize a cronjob to start when you for example reboot your server.
~/eggdrop/autobotchk fsfbot.conf -30 -noemail

# "Use 'crontab -l' to view all your current crontab entries"
crontab -l

Final thoughts:

Look into the fsfbot.conf file, there are so many options there. For example, you might want to use a DCC instead of Telnet, or configure some SSL options. The guy who helped me recommended these settings in the conf file but I was to overloaded to take notes of everything:
set raw-log 1
set opchars "@&~"


Useful links:
http://www.egghelp.org/commands/index.htm
http://suninet.the-demon.de/
http://eggwiki.org/Eggdrop.conf
http://www.eggheads.org/
http://docs.eggheads.org/mainDocs/tcl-commands.html
http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm
http://tclhelp.net/#faqcolor
http://forum.egghelp.org/viewtopic.php?p=95379#95379

#####################################################################
Useful commands

make the bot send message:
putserv "privmsg #fsf :whatever you want to say, goes here"

# the proper say to shut down bot is with a command NOT  kill <pid>
.help die
.die

# to get a little report
.status

# Join a channel. Adding chans in .conf file is deprecated
.+chan #whateverCHanNameHere

# Diconnect from a channel
.-chan #channelname

# Send message in channel
.say #somechannel text goes here

# Switch channel
.console #somechannel

# same for  when you want to unload a script.   if you comment out a source line, or delete is, you need to  .restart to effect the unload.
# You need to restart if you modify the bind commands to
.restart

# to make bot read in changes... for new scripts, edited scripts, or edited eggdrop.conf. .rehash  saves your bot leaving all the chans it is in, and having to rejoin
.rehash

# to list cron binds loaded in bot, right now
.binds cron

#### evaluate the commands in your script

# List the procs
.tcl info procs

# Execute the procname
.tcl <procname>

.match *

#fsf objectives

IRC Friday Meeting hourly reminders

set fsf_channel__channel_name "#fsf"
set fsf_channel__channel_message_repeat_message "If it is your first time joining us, please check out the participation guide: https://directory.fsf.org/wiki/Free_Software_Directory:Participate"

bind cron - "0 12 * * 5" fsf_channel__channel_message__start_meeting
bind cron - "0 13 * * 5" fsf_channel__channel_message__second_hour
bind cron - "0 14 * * 5" fsf_channel__channel_message__third_hour
bind cron - "0 15 * * 5" fsf_channel__channel_message__stop_meeting

# Start meeting
proc fsf_channel__channel_message__start_meeting {min hour day month weekday} {
	global fsf_channel__channel_name fsf_channel__channel_message_repeat_message
	putserv "privmsg $fsf_channel__channel_name :The Free Software Directory meeting starts now. $fsf_channel__channel_message_repeat_message"
}

# Second hour
proc fsf_channel__channel_message__second_hour {min hour day month weekday} {
	global fsf_channel__channel_name fsf_channel__channel_message_repeat_message
	putserv "privmsg $fsf_channel__channel_name :We're are entering the second hour of the Free Software Directory meeting. $fsf_channel__channel_message_repeat_message"
}

# Third hour
proc fsf_channel__channel_message__third_hour {min hour day month weekday} {
	global fsf_channel__channel_name fsf_channel__channel_message_repeat_message
	putserv "privmsg $fsf_channel__channel_name :We're are entering the third hour of the Free Software Directory meeting. $fsf_channel__channel_message_repeat_message"
}

# Stop meeting
proc fsf_channel__channel_message__stop_meeting {min hour day month weekday} {
	global fsf_channel__channel_name fsf_channel__channel_message_repeat_message
	putserv "privmsg $fsf_channel__channel_name :The Free Software Directory meeting stops now. $fsf_channel__channel_message_repeat_message"
}

Approved revisions

TODO



Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.