This commit is contained in:
deathbybandaid 2019-09-23 12:09:37 -04:00
parent 183bf4b637
commit 8b410b51f7
5 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,53 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
"""This is a method to read files, online and local, and cache them"""
import os
from .Read import read as botread
from .Database import db as botdb
class BotNotes():
def __init__(self):
self.notes = botdb.get_plugin_value('SpiceBot_Release_Notes', 'notes') or dict()
self.dir_to_scan = botread.get_config_dirs("SpiceBot_Release_Notes")
self.load_txt_files(self.dir_to_scan)
self.save_notes()
def save_notes(self):
savenotes = {}
for notefile in list(self.notes.keys()):
savenotes[notefile] = {"old": self.notes[notefile]["old"]}
botdb.set_plugin_value('SpiceBot_Release_Notes', 'notes', savenotes)
def load_txt_files(self, dir_to_scan):
# iterate over files within
for directory in dir_to_scan:
for file in os.listdir(directory):
filepath = os.path.join(directory, file)
filepath = os.path.join(directory, file)
if os.path.isfile(filepath) and filepath.endswith('.txt'):
# gather file stats
slashsplit = str(filepath).split("/")
filename = slashsplit[-1]
filename_base = str(os.path.basename(filename).rsplit('.', 1)[0]).lower()
if filename_base not in list(self.notes.keys()):
self.notes[filename_base] = {}
if "old" not in list(self.notes[filename_base].keys()):
self.notes[filename_base]["old"] = []
if "new" not in list(self.notes[filename_base].keys()):
self.notes[filename_base]["new"] = []
text_file = open(filepath, 'r')
lines = text_file.readlines()
for line in lines:
if str(line) not in self.notes[filename_base]["old"]:
self.notes[filename_base]["new"].append(str(line))
self.notes[filename_base]["old"].append(str(line))
text_file.close()
releasenotes = BotNotes()

View File

@ -39,6 +39,7 @@ from .Read import *
from .Translate import *
from .Version import *
from .RegNicks import *
from .ReleaseNotes import *
__author__ = 'Sam Zick'

View File

@ -0,0 +1 @@
First release of Release Notes

View File

@ -0,0 +1,21 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
"""
This is the SpiceBot Users system.
"""
import sopel
import sopel_modules.SpiceBot as SpiceBot
from sopel_modules.spicemanip import spicemanip
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('releasenotes')
def nickname_comand_releasenotes(bot, trigger, botcom):
newnotes = False
for notefile in list(SpiceBot.releasenotes.notes.keys()):
if len(SpiceBot.releasenotes.notes[notefile]["new"]):
bot.osd(["[" + str(notefile) + "]", spicemanip(SpiceBot.releasenotes.notes[notefile]["new"], 'andlist')])
newnotes = True
if not newnotes:
bot.osd("This bot restart contains no new release notes.")

View File

@ -24,6 +24,7 @@ from .DictComs import *
from .TODO import *
from .Version import *
from .RegNicks import *
from .ReleaseNotes import *
__author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net'