Skip to content

Todo Task plugin is added. #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ GUI clients are used to manage plugins, launch bot as well as specify credential
- ❓ 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
- :page_with_curl: comic by [@mboekhold](https://github.com/mboekhold) - returns a random comic
- 📝 todo by [@h-ranjan1110](https://github.com/h-ranjan1110) - Makes a to do list .

## Docker
### Building Docker image
Expand Down
127 changes: 127 additions & 0 deletions honeybot/plugins/todo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
"""
[todo.py]
Todo list Plugin

[Author]
Himanshu Ranjan

[Website]
https://github.com/h-ranjan1110

[About]
Todo list keeps all your pending task .
You can add a task ,delete or show list.
This list is stored in a text file called todo.txt in honeybot directory.
If this does not exist it creates one.

[Commands]
>>>.todo add <Your Task Here>
It adds the task to do the todo list.

>>>.todo delete <index>
To delete a task input it's index number as shown in the list.

>>>.todo show
It shows all the task currently on the list.

>>>.todo clear
This will delete all the task in the list.

>>>.todo help
sends messages explaining how to use the todo plugin
"""

import requests
import os

if not os.path.exists('todo.txt'):
""" Creating todo.txt is it is not already present. """
todo = open("todo.txt", "w+")
todo.close()


class Plugin:
def __init__(self):
pass

def get_help(info, methods):
""" help function to give information about commands."""
methods['send'](info['address'], ".todo add <Your Task Here> \
(It adds the task to do the todo list.)")
methods['send'](info['address'], ".todo delete <index> \
(To delete a task input it's index number as shown in the list.)")
methods['send'](info['address'], ".todo show \
(It shows all the task currently on the list.)")
methods['send'](info['address'], ".todo clear \
(This will delete all the task in the list.)")
methods['send'](info['address'], ".todo help \
(sends messages explaining how to use the todo plugin.)")

def showlist(info, methods):
""" It prints the todo file on the screen """
# Parse the user ID from info['prefix']
raw_user = info['prefix']
user_index = raw_user.find('!')
user = raw_user[0:user_index]

if os.stat("todo.txt").st_size == 0:
methods['send'](info['address'], "Awesome " + user + ". You Have No Task Pending!")
else:
methods['send'](info['address'], "Hi, " + user + ". These are your tasks.")
with open("todo.txt", "r") as f:
lines = f.readlines()
count = 1
for line in lines:
methods['send'](info['address'], str(count) + ". " + line)
count = count + 1

def run(self, incoming, methods, info, bot_info):
""" Handling of requests from user."""
try:
msgs = info['args'][1:][0].split()

if info['command'] == 'PRIVMSG' and msgs[0] == '.todo':

# adding new task to beginning of list
if msgs[1] == 'add':
task_start_index = 9
task = info['args'][1:][0][task_start_index:]
with open("todo.txt", 'r+') as todo:
content = todo.read()
todo.seek(0, 0)
todo.write(task.rstrip('\n') + '\n' + content)
Plugin.showlist(info, methods)

# deleting the line of given index
elif msgs[1] == 'delete':
line_no = int(msgs[2])

with open("todo.txt", "r") as f:
lines = f.readlines()

count = 1
with open("todo.txt", "w") as f:
for line in lines:
if count != line_no:
f.write(line)
count = count + 1
Plugin.showlist(info, methods)

# Deleting all the task . todo.txt file is not deleted
elif msgs[1] == "clear":
open('todo.txt', 'w').close()
Plugin.showlist(info, methods)

# Displaying all task in file .
elif msgs[1] == "show":
Plugin.showlist(info, methods)

# Showing help
elif msgs[1] == "help":
Plugin.get_help(info, methods)
else:
methods['send'](info['address'], "Please Select A Valid Option")

except Exception as e:
print('woops plugin', __file__, e)
1 change: 1 addition & 0 deletions honeybot/settings/PLUGINS.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ password_generator
comic
transfer-rumour
pynews
todo