Skip to content

Commit

Permalink
Move bot configuration to environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dentarg committed Mar 20, 2014
1 parent 3caa3ae commit 951ea7b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*.pyc
.env
30 changes: 30 additions & 0 deletions README.md
@@ -0,0 +1,30 @@
# pynik

A Python IRC bot.

## Environment variables

Configure your bot with environment variables:

| Environment variable | Description |
|------------------------|---------------------------------------------------|
| SERVER | IRC server the bot should connect to. |
| SERVER_PORT | IRC server port. |
| NICK | Nickname of the bot. |
| USERNAME | Username part of the bot hostmask. |
| REALNAME | Real name of the bot. |
| ADMINS | Nicknames with bot admin privileges. |
| CHANNELS | Channels the bot should join on start. |

If put the environment variables in a file named `.env`, you can use [Honcho]
to start the bot.

Install Honcho if you don't have it

pip install honcho

Start the bot

honcho run python main.py

[Honcho]: https://github.com/nickstenning/honcho
4 changes: 2 additions & 2 deletions plugins/auto_join.py
Expand Up @@ -2,6 +2,7 @@

import sys
import time
import settings
from plugins import Plugin

def get_plugins():
Expand All @@ -12,8 +13,7 @@ def __init__(self):
pass

def on_connected(self, bot):
channels = ['#anime.ava', '#starkast', '#c++.se', '#ryd', '#python.se', '#teeworlds-dev', '#teeworlds', '#stalverk80', '#botnik', '#warpdrive', '#d08', '#java.se', '#d1d', '#hardstyle.se', '#johnbauer', '#d2006', '#d09', '#lithen', '#wow.mm']
#channels = ['#botnik']
channels = settings.channels

for channel in channels:
bot.join(channel)
3 changes: 2 additions & 1 deletion plugins/utility.py
Expand Up @@ -9,6 +9,7 @@
import os
import signal
import string
import settings

class TimeoutException(Exception):
pass
Expand Down Expand Up @@ -138,7 +139,7 @@ def load_data(name, default_value=None):
return default_value

def has_admin_privileges(source, target):
return source in ['serp', 'teetow', 'Merola']
return source in settings.admins

nbsp_latin1 = unescape(" ")
nbsp_utf8 = nbsp_latin1.decode("latin-1").encode("utf-8")
Expand Down
13 changes: 8 additions & 5 deletions settings.py
@@ -1,6 +1,9 @@
server_address = "port80.se.quakenet.org"
server_port = 6667
import os

nick = "CHANGEME"
username = "CHANGEME"
realname = "CHANGEME"
server_address = os.environ['SERVER']
server_port = int(os.environ['SERVER_PORT'])
nick = os.environ['NICK']
username = os.environ['USERNAME']
realname = os.environ['REALNAME']
admins = os.environ['ADMINS'].split(',')
channels = os.environ['CHANNELS'].split(',')

0 comments on commit 951ea7b

Please sign in to comment.