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

Commit

Permalink
Merge pull request #9 from AngeloGiacco/master
Browse files Browse the repository at this point in the history
syncro
  • Loading branch information
AngeloGiacco committed Apr 18, 2019
2 parents cac45ea + 6552ee8 commit 6c17d0b
Show file tree
Hide file tree
Showing 14 changed files with 666 additions and 228 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Psst. since i learnt py through this bot, we decided to keep a new-comers friend

## 📌 Contributing Countries

🇲🇺 🇺🇸 🇨🇦 🇦🇷 🇮🇳 🇬🇧 🇬🇬
🇲🇺 🇺🇸 🇨🇦 🇦🇷 🇮🇳 🇬🇧 🇬🇬 🇧🇷

## 📨 Follow the project on CodeTriage for updates!

Expand Down Expand Up @@ -84,8 +84,12 @@ who have never contributed to a project before, and Abdur-Rahmaan Janhangeer was
- 🕵️‍ riddle by [@AngeloGiacco](https://github.com/AngeloGiacco) - returns a random riddle
- 🗞 news by [@AngeloGiacco](https://github.com/AngeloGiacco) - gets the top 10 headlines from bbc world news
- 📝 horoscope by [@AngeloGiacco](https://github.com/AngeloGiacco) - gets your daily horoscope for your starsign
- 💵 currency converter by [@AngeloGiacco](https://github.com/AngeloGiacco) - converts currencies
- 🔫 russian_roulette by [@AngeloGiacco](https://github.com/AngeloGiacco) - may or may not kick you off the channel
- 🎲 roll by [@GlennToms](https://github.com/GlennToms) - rolls a dice
- ❓ help by [@edumello](https://github.com/edumello) - show link to plugin's information page
- ✅ channeljoin by [@marceloyb](https://github.com/marceloyb) - join command for bot


## 🔧 Plugins Development

Expand Down
38 changes: 38 additions & 0 deletions honeybot/plugins/channeljoin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""
[channeljoin.py]
Join Plugin
[Author]
Marcelo Benesciutti
[About]
Bot Will join a given channel in the server
[Commands]
>>> .channeljoin channel
bot joins the given channel
"""

class Plugin:
def __init__(self):
pass

def run(self, incoming, methods, info):
try:
msgs = info['args'][1:][0].split()
if info['command'] == 'PRIVMSG' and msgs[0] == '.channeljoin':
raw_user = info['prefix']
user_index = raw_user.find('!')
user = raw_user[0:user_index]
with open("settings/OWNERS.conf", "r") as f:
for owner in f:
if owner.strip() == user:
methods['join'](msgs[1])
break
else:
methods['send'](info["address"], "only bot owners can execute this function, " +\
"make sure your IRC nickname is in the settings/OWNERS.conf file")

except Exception as e:
print('woops plugin error: ', e)
80 changes: 80 additions & 0 deletions honeybot/plugins/converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
[converter.py]
Currency Converter Plugin
[Author]
Angelo Giacco
[About]
Gets the top 10 headlines around the world from bbc world news
[Commands]
>>> .convert <<base currency code>> <<target currency code>> <<amount>>
returns the conversion: amount argument is optional with a default of 1
.convert help
shows a list of currencies supported
"""
import requests
import math
from bs4 import BeautifulSoup

class Plugin:
def __init__(self):
pass

currencies = ["GBP","EUR","USD","ARS","AUD","BHD","BWP","BRL","BND",
"BGN","CAD","CLP","CNY","COP","HRK","CZK","DKK","HKD",
"HUF","ISK","INR","IDR","IRR","ILS","JPY","KZT","KRW",
"KWD","LYD","MYR","MUR","MXN","NPR","NZD","NOK","OMR",
"PKR","PHP","PLN","QAR","RON","RUB","SAR","SGD","ZAR",
"LKR","SEK","CHF","TWD","THB","TTD","TRY","AED"]

def help(self, methods, info):
methods['send'](info['address'],"showing supported currencies")
currency_lists = [Plugin.currencies[5*i:5*i+5] for i in range(0,math.ceil(len(Plugin.currencies)/5))]
for currency_list in currency_lists:
methods['send'](info['address']," ".join(currency_list))

def conv(self, base_cur, target_cur, amount = "1"):
def is_number(char):
try:
float(char)
return True
except ValueError:
return False
base_cur = base_cur.upper()
target_cur = target_cur.upper()
if base_cur not in Plugin.currencies or target_cur not in Plugin.currencies:
return "one of the currencies is invalid. enter .converter help to see supported currencies"
elif not (is_number(amount)):
return "invalid amount entered, it must be a number. default is 1"
else:
base_url = "https://www.x-rates.com/calculator/?"
url = base_url + "from=" + base_cur + "&to="+target_cur + "&amount="+str(amount)
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')

part1 = soup.find(class_="ccOutputTrail").previous_sibling
part2 = soup.find(class_="ccOutputTrail").get_text(strip=True)
converted = "{}{}".format(part1,part2)
return str(amount)+ base_cur +" is equal to "+converted+target_cur

def run(self, incoming, methods, info):
try:
msgs = info['args'][1:][0].split()
if info['command'] == 'PRIVMSG' and msgs[0] == '.convert':
if len(msgs) == 3:
methods['send'](info['address'], Plugin.conv(self,msgs[1],msgs[2]))
elif len(msgs) == 4:
methods['send'](info['address'], Plugin.conv(self,msgs[1],msgs[2],msgs[3]))
elif len(msgs) == 2 and msgs[1] == "help":
methods['send'](info['address'],Plugin.help(self, methods, info))
elif len(msgs) == 2 and msgs[1] != "help":
methods['send'](info['address'],"if only two arugments sent, second argument must be help")
elif len(msgs) > 4:
methods['send'](info['address'],"too many arguments")
methods['send'](info['address'],"either two currencies with an optional amount")
methods['send'](info['address'],"or help")
elif len(msgs) == 1:
methods['send'](info['address'],"converter plugin requires arguments:")
methods['send'](info['address'],"either two currencies with an optional amount")
methods['send'](info['address'],"or help")
except Exception as e:
print('woops news plugin error ', e)
3 changes: 2 additions & 1 deletion honeybot/plugins/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def run(self, incoming, methods, info):
dict = PyDictionary()
word = str(msgs[1])
defin = dict.meaning(word)['Noun']
methods['send'](info['address'], '{}'.format(defin))
for definition in defin:
methods['send'](info['address'], definition)
except Exception as e:
print('woops plug', e)
27 changes: 27 additions & 0 deletions honeybot/plugins/echo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
[echo.py]
Echo Plugin
[Author]
Angelo Giacco
[About]
Bot will message channel what you write after '.echo'
Very simple but also useful for testing plugins that require more than one person
Created when developing monopoly plugin
[Commands]
.echo <<stuff>>
sends stuff to channel from bot
"""

class Plugin:
def __init__(self):
pass

def run(self,incoming,methods,info):
try:
msgs = info['args'][1:][0].split(" ")
if info["command"] == "PRIVMSG" and msgs[0] == ".echo":
message = " ".join(msgs[1:])
methods['send'](info['address'],message)
except Exception as e:
print("woops echo plugin error",e)
31 changes: 23 additions & 8 deletions honeybot/plugins/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,31 @@ def run(self, incoming, methods, info):
if info['command'] == 'PRIVMSG':
if len(msgs) > 1:
if msgs[0] == '.sin':
sine = math.sin(int(msgs[1]))
methods['send'](info['address'], '{}'.format(sine))
try:
sine = math.sin(float(msgs[1]))
methods['send'](info['address'], '{}'.format(sine))
except ValueError:
methods['send'](info['address'], ".sin must have numbers")
elif msgs[0] == '.cos':
cosine = math.cos(int(msgs[1]))
methods['send'](info['address'], '{}'.format(cosine))
try:
cosine = math.cos(float(msgs[1]))
methods['send'](info['address'], '{}'.format(cosine))
except ValueError:
methods['send'](info['address'], ".cos must have numbers")
elif msgs[0] == '.tan':
tangent = math.tan(int(msgs[1]))
methods['send'](info['address'], '{}'.format(tangent))
try:
tangent = math.tan(float(msgs[1]))
methods['send'](info['address'], '{}'.format(tangent))
except ValueError:
methods['send'](info['address'], ".tan must have numbers")
elif msgs[0] == '.rand':
rand = random.randint(int(msgs[1]), int(msgs[2]))
methods['send'](info['address'], '{}'.format(rand))
try:
if int(msgs[1]) >= int(msgs[2]):
methods['send'](info['address'], ".rand requires two integers that are not equal and the first must be biggest")
else:
rand = random.randint(int(msgs[1]), int(msgs[2]))
methods['send'](info['address'], '{}'.format(rand))
except ValueError:
methods['send'](info['address'], ".rand must have numbers")
except Exception as e:
print('\n*error*\nwoops plugin', __file__, e, '\n')
Loading

0 comments on commit 6c17d0b

Please sign in to comment.