Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdur-rahmaanJ committed Feb 19, 2019
1 parent 0f02355 commit 0afb568
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 10 deletions.
5 changes: 5 additions & 0 deletions honeybot/CONNECT.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[INFO]

server_url = chat.freenode.net
port = 6667
name = appinventormuBot
3 changes: 2 additions & 1 deletion honeybot/PLUGINS.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ joke
maths
calc
conv_sniff
caesar_cipher
caesar_cipher
debug
4 changes: 4 additions & 0 deletions honeybot/lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from main import Bot_core as Bot

bot = Bot()
print(bot.specific_send_command('#abc', 'greetings'))
23 changes: 14 additions & 9 deletions honeybot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import socket
import os
import importlib
import configparser

config = configparser.ConfigParser()
config.read('CONNECT.conf')
plugins = []


class Bot_core(object):
def __init__(self,
server_url='chat.freenode.net',
port=6667,
name='appinventormuBot',
server_url=config['INFO']['server_url'],
port=int(config['INFO']['port']),
name=config['INFO']['name'],
owners=['appinventorMu', 'appinv'],
password='',
friends=['haruno', 'keiserr', 'loganaden'],
Expand Down Expand Up @@ -43,7 +46,7 @@ def set_nick_command(self):
return 'NICK ' + self.name + '\r\n'

def present_command(self):
return 'USER ' + self.name + ' ' + self.name + ' ' +
return 'USER ' + self.name + ' ' + self.name + ' ' +\
self.name + ' : ' + self.name + ' IRC\r\n'

def identify_command(self):
Expand Down Expand Up @@ -131,6 +134,9 @@ def methods(self):
}

def run_plugins(self, listfrom, incoming):
'''
incoming is the unparsed string. refer to test.py
'''
for plugin in listfrom:
plugin.run(incoming, self.methods(), self.info(incoming))

Expand Down Expand Up @@ -173,8 +179,7 @@ def pull(self):
""".format(msg))
if len(data) == 0:
try:
self.irc.close()
self.registered_run()
print('<must handle reconnection>')
except Exception as e:
print(e)
except Exception as e:
Expand Down Expand Up @@ -210,6 +215,6 @@ def stay_alive(self, incoming):
'''.format(part[1]))
self.irc.recv(2048).decode("UTF-8")


x = Bot_core()
x.registered_run()
if __name__ == '__main__':
x = Bot_core()
x.registered_run()
30 changes: 30 additions & 0 deletions honeybot/plugins/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
[debug.py]
Debug plugin : Un
[Author]
Abdur-Rahmaan Janhangeer, pythonmembers.club
[About]
prints all parameters passed to bot
[Commands]
>>> .debug
prints all parameters
"""


class Plugin:
def __init__(self):
pass

def run(self, incoming, methods, info):
try:
# if '!~' in info['prefix']:
# print(info)
if info['command'] == 'PRIVMSG' and info['args'][1] == '.debug':
methods['send'](info['address'], info['prefix'])
except Exception as e:
print('woops plug', e)

104 changes: 104 additions & 0 deletions honeybot/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import unittest
import configparser
from main import Bot_core as Bot
'''
':appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.197.227.66.197 PRIVMSG ##bottestingmu :ef'
{
'prefix': 'appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.197.227.66.197',
'command': 'PRIVMSG',
'address': '##bottestingmu',
'args': ['##bottestingmu', 'ef']
}
'''
config = configparser.ConfigParser()
config.read('CONNECT.conf')

# incoming
incoming = ':appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200 PRIVMSG ##bottestingmu :ef'
bot = Bot()


class HoneybotTests(unittest.TestCase):
'''
basic info
'''
def test_name(self):
self.assertEqual(
bot.name,
config['INFO']['name'])

def test_server_url(self):
self.assertEqual(
bot.server_url,
config['INFO']['server_url'])

def test_port(self):
self.assertEqual(
bot.port,
int(config['INFO']['port']))
'''
info function
'''
def test_info_prefix(self):
self.assertEqual(
bot.info(incoming)['prefix'],
'appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200')

def test_info_command(self):
self.assertEqual(
bot.info(incoming)['command'],
'PRIVMSG')

def test_info_address(self):
self.assertEqual(
bot.info(incoming)['address'],
'##bottestingmu')

def test_info_args(self):
self.assertEqual(
bot.info(incoming)['args'],
['##bottestingmu', 'ef'])

'''
commands
'''
def test_set_nick_command(self):
self.assertEqual(
bot.set_nick_command(),
'NICK {0}\r\n'.format(config['INFO']['name'])
)

def test_present_command(self):
self.assertEqual(
bot.present_command(),
'USER {0} {0} {0} : {0} IRC\r\n'.format(config['INFO']['name'])
)

def test_identify_command(self):
self.assertEqual(
bot.identify_command(),
'msg NickServ identify \r\n'
)

def test_join_command(self):
self.assertEqual(
bot.join_channel_command('#abc'),
'JOIN #abc \r\n'
)

def test_specific_send_command(self):
self.assertEqual(
bot.specific_send_command('#abc', 'greetings'),
'PRIVMSG #abc :greetings\r\n'
)

def test_pong_return(self):
self.assertEqual(
bot.pong_return(),
'PONG \r\n'
)



if __name__ == '__main__':
unittest.main()

0 comments on commit 0afb568

Please sign in to comment.