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

Email Plugin #62

Merged
merged 6 commits into from Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions README.md
@@ -1,8 +1,8 @@
[![first-timers-only](https://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square)](https://www.firsttimersonly.com/)
![Open Source Love](https://img.shields.io/badge/Open%20Source-%E2%9D%A4-pink.svg)
![Open Source Love](https://img.shields.io/badge/Open%20Source-%E2%9D%A4-pink.svg)
![MadeinMoris](https://img.shields.io/badge/Made%20in-Moris-green.svg)

# 🍯 honeybot py
# 🍯 honeybot py

## 📮 About
HoneyBot is a python-based IRC bot. (**python3**)
Expand Down Expand Up @@ -32,7 +32,7 @@ get issues delivered in your inbox.
* 🛰️ keyword parameters
* 🌵 password security with config file [disabled for now]
* 🔌 now with plugins

## ⌚ Current Plugins

- 💎 bitcoin by [@Macr0Nerd](https://github.com/Macr0Nerd) - get price of bitcoin
Expand All @@ -52,7 +52,7 @@ get issues delivered in your inbox.
- 🗿 translate by Ahmed Deeb - google translate plugin
- 📑 test by [@Abdur-rahmaanJ](https://github.com/Abdur-rahmaanJ) - runs tests
- ⛅️ weather by [@Macr0Nerd](https://github.com/Macr0Nerd) - returns weather info for a given location

- ✉️ mail by [@TannerFry](https://github.com/TannerFry) - send emails within the chat
## 📃 Contributing Guide

- don't forget to add your country flag here after accepted PR. i'll have to hunt it down on your profile if not.
Expand All @@ -62,7 +62,7 @@ get issues delivered in your inbox.

different changes to different files. for example, someone making a weather plugin first he creates a new branch
```
git checkout -b "weather-plugin"
git checkout -b "weather-plugin"
```
then he commits
```
Expand All @@ -75,7 +75,7 @@ git push origin head
```
now let us say he wants to work on another issue, adding a joke in the jokes plugin, he creates another branch
```
git checkout -b "add-jokes"
git checkout -b "add-jokes"
```
after, same as before
```
Expand All @@ -87,7 +87,7 @@ now he wants to fix his weather plugin, he changes branch
```
git checkout weather-plugin
```
works, then commit
works, then commit
```
git add *
git commit -m "fixed <issue>"
Expand All @@ -108,7 +108,7 @@ Now, other changes are ongoing, what if you need the latest changes?
git pull origin master
```
helps if you cloned your own repo. What is you want to update your local copy of someone else repo?
you do it like that
you do it like that

```
cd <your/local/cloned/repo/path/here>
Expand Down Expand Up @@ -193,7 +193,7 @@ hence
if info['command'] == 'PRIVMSG' and info['args'][1] == '.hi':
methods['send'](info['address'], 'hooo')
```
from above means
from above means
```
if message received == .hi:
send(address, message)
Expand All @@ -216,7 +216,7 @@ name = appinventormuBot
## 🔌 Todo Plugins
- [x] 💐 humour
- [x] 🌨️ weather
- [ ] ✉️ mail
- [x] ✉️ mail
- [x] 🎛️ maths
- [ ] 📥 pm when user online

Expand All @@ -235,4 +235,3 @@ https://discord.gg/E6zD4XT

## 🖊 Credits
[@arwinneil](https://github.com/arwinneil) for opensource and madeinmoris badges

2 changes: 1 addition & 1 deletion honeybot/CONNECT.conf
Expand Up @@ -2,4 +2,4 @@

server_url = chat.freenode.net
port = 6667
name = hb_tst00
name = hb_tst00
3 changes: 2 additions & 1 deletion honeybot/PLUGINS.conf
Expand Up @@ -11,4 +11,5 @@ dictionary
password_generator
bitcoin
wikipedia
weather
weather
mail
21 changes: 21 additions & 0 deletions honeybot/email_config.conf
@@ -0,0 +1,21 @@
#put your email to send from after "Email: ", make sure that there is atleast 1 space
#between "Email:" and your email.

Email: email@email.com

#put your email password and make sure that there is at least 1 space between "Password:"
#and your password

Password: password

#put your email service provider's SMTP server. The default will be "smtp.office365.com"
#which is used for outlook and hotmail emails. Make sure there is at least 1 space between
#"Server:" and the server name.

SMTP Server: smtp.office365.com

#put your email service provider's SMTP server's port. The default will be "587" which
#is the port for the "smtp.office365.com". Make sure there is at least 1 space between
#"Port:" and the port number.

SMTP Server Port: 587
4 changes: 3 additions & 1 deletion honeybot/plugins/dictionary.py
Expand Up @@ -8,13 +8,15 @@

[About]
sends the meaning of the word
requires PyDictionary to be installed
can use pip -> "pip install PyDictionary"

[Commands]
>>> .dictionary <<word>>
returns meaning of the word specified
"""

from PyDictionary import PyDictionary
import PyDictionary


class Plugin:
Expand Down
116 changes: 116 additions & 0 deletions honeybot/plugins/mail.py
@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-
"""
[mail.py]
Email plugin

[Author]
Tanner Fry

[About]
Will allow the user to send an email while in the chat
with the bot. The text send will be interpreted as html
so you can use formatting such as <br> to make new lines,
and any other html formatting commands in the text of the
body of the email. No additional libraries need to be installed.
Make sure that you configure the email_config.conf file with your
email, your email password, SMTP server, and SMTP server port.
See that document for more information.

[Commands]
.mail <To email address> .body <Text for the body of your email> .subject <Text of subject for email>
EX:// ".mail test@email.com .body testing body for honeybot email .subject testing subject"

"""
import smtplib
import string
from email.mime.text import MIMEText

#open config file for user credentials to email
f = open("email_config.conf")
str = f.read()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with open():
    ...

recommended here

f.close()

#split the read in words into a list, and pop them into their respective
#variables
test = str.rsplit()
USER = test[test.index("Email:")+1]
PASS = test[test.index("Password:")+1]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using config parser better here

HOST = test[test.index("Server:")+1]
PORT = test[test.index("Port:")+1]

#used to tie into the body of what the user sends, if this is not at the
#front of the message then the message will not appear in the email
text = "\n"

class Plugin:
def __init__(self):
pass

#__email will take 6 parameters to setup the email reconnection
#and send the message.
def __email(HOST, PORT, USER, PASS, TO, MSG):
server = smtplib.SMTP(HOST, int(PORT))
server.connect(HOST, int(PORT))
server.starttls()
server.login(USER, PASS)
server.sendmail(USER, TO, MSG.as_string())
server.quit()

#body is used to loop through the msgs list from the chat
#and grab everything that was said after .body and before
#.subject.
def body(BODY_INDEX,SUBJECT_INDEX, msgs):
i = BODY_INDEX+1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a .split?

while i < SUBJECT_INDEX:
if i == BODY_INDEX + 1:
if msgs[i] == "\n":
Body = msgs[i]
BODY = msgs[i] + " "
elif i == SUBJECT_INDEX - 1:
BODY = BODY + msgs[i]
else:
if msgs[i] == "\n":
Body = BODY + msgs[i]
BODY = BODY + msgs[i] + " "
i = i+1
return (BODY)

#subject is used to loop through the msgs list from the chat
#and grab everythin after .subject and before the end of the
#message
def subject(SUBJECT_INDEX, MAX_INDEX, msgs):
i = SUBJECT_INDEX + 1
while i < MAX_INDEX:
if i == SUBJECT_INDEX + 1:
SUBJECT = msgs[i] + " "
elif i == MAX_INDEX - 1:
SUBJECT = SUBJECT + msgs[i]
else:
SUBJECT = SUBJECT + msgs[i] + " "
i = i+1
return (SUBJECT)

def run(self, incoming, methods, info):
try:
# if '!~' in info['prefix']:
# print(info)
msgs = info['args'][1:][0].split()
if info['command'] == 'PRIVMSG':
#makes sure the first parameter is ".mail"
if msgs[0] == '.mail':
TO = msgs[1] #grabs the TO email provided
BODY_INDEX = msgs.index(".body") #gets index for ".body", used in body function
SUBJECT_INDEX = msgs.index(".subject") #gets index for ".subject" used in body, and subject functions
MAX_INDEX = len(msgs) #gets max index to know the max indexing value

BODY = Plugin.body(BODY_INDEX,SUBJECT_INDEX, msgs) #fill the BODY string using the body function to extraxt the text
SUBJECT = Plugin.subject(SUBJECT_INDEX, MAX_INDEX, msgs) #fill the SUBJECT string using the subject function to extract the text

MSG = MIMEText(text + BODY, 'html') #sets MSG format to html, and fills in the BODY portion
MSG["Subject"] = SUBJECT #Fills the MSG's subject with SUBJECT
MSG["From"] = USER #Fills the From field with USER string
MSG["To"] = TO #Fills the TO field with the TO string
Plugin.__email(HOST, PORT, USER, PASS, TO, MSG) #Passes paramters needed to __email to be able to start up connection to SMTP server and send message

except Exception as e:
print('\n*error*\nwoops plugin', __file__, e, '\n')
1 change: 0 additions & 1 deletion honeybot/plugins/maths.py
Expand Up @@ -35,7 +35,6 @@ def run(self, incoming, methods, info):
# if '!~' in info['prefix']:
# print(info)
msgs = info['args'][1:][0].split()
# print(msgs)
if info['command'] == 'PRIVMSG':
if len(msgs) > 1:
if msgs[0] == '.sin':
Expand Down
18 changes: 9 additions & 9 deletions honeybot/plugins/password_generator.py
Expand Up @@ -30,19 +30,19 @@ class Plugin:
def __init__(self):
pass

def __passgen(self, password_length):
def __passgen(password_length):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(password_length))

def __passgenalphanum(self, password_length):
def __passgenalphanum(password_length):
password_characters = string.ascii_letters + string.digits + string.punctuation
return ''.join(random.choice(password_characters) for i in range(password_length))

def __passgensecure(self, password_length):
def __passgensecure(password_length):
password_characters = string.ascii_letters + string.digits + string.punctuation
return ''.join(secrets.choice(password_characters) for i in range(password_length))

def __passgenspecialchar(self, password_length):
def __passgenspecialchar(password_length):
randomSource = string.ascii_letters + string.digits + string.punctuation
password = random.choice(string.ascii_lowercase)
password += random.choice(string.ascii_uppercase)
Expand All @@ -64,17 +64,17 @@ def run(self, incoming, methods, info):
if len(msgs) > 1:
if msgs[0] == '.passgen':
length = msgs[1]
methods['send'](info['address'], self.__passgen(length))
methods['send'](info['address'], Plugin.__passgen(int(length)))
if msgs[0] == '.passgensecure':
length = msgs[1]
methods['send'](info['address'], self.__passgensecure(length))
methods['send'](info['address'], Plugin.__passgensecure(int(length)))
if msgs[0] == '.passgenalphanum':
length = msgs[1]
methods['send'](info['address'], self.__passgenalphanum(length))
methods['send'](info['address'], Plugin.__passgenalphanum(int(length)))
if msgs[0] == '.passgenspecialchar':
length = msgs[1]
if length >= 4:
methods['send'](info['address'], self.__passgenspecialchar(length))
if int(length) >= 4:
methods['send'](info['address'], Plugin.__passgenspecialchar(int(length)))
else:
raise Exception('Length of password should be greater than 4.')
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions honeybot/plugins/wikipedia.py
Expand Up @@ -8,6 +8,7 @@

[About]
sends a wikipedia article on request based off of a search or random query
requires wikipedia library. Can use pip -> "pip install wikipedia"

[Website]
https://Macr0Nerd.github.io
Expand Down
4 changes: 4 additions & 0 deletions honeybot/plugins_info.md
Expand Up @@ -62,3 +62,7 @@ Returns a private trivia question
by Kyle Galloway\
encrypts and decrypts using a caesar cipher

# mail.py
by Tanner Fry
send an email using the following command format:
.mail <To email address> .body <Text for the body of your email> .subject <Text of subject for email>