Skip to content

Commit

Permalink
See the releases section for full change list
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmars committed Oct 11, 2015
1 parent 4d12905 commit 82faf2d
Show file tree
Hide file tree
Showing 19 changed files with 411 additions and 55 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
(29.09.2015) v0.0.0 - Initial commit
(06.10.2015) v1.0.0 - Initial commit to github
(29.09.2015) v0.0.0
+ Initial commit
(06.10.2015) v1.0.0
+ Initial commit to github
+ A bot that allows connecting to a cbot.ws chatbox and implements various plugins
(11.10.2015) v1.1.0
+) You can now set plugin settings from CLI (if they implement the function)
+) Implemented privilege system for plugins.
+) New default plugin - Time manager. Either outputs current time (in any time zone) or time until a specified time/date.
+) New default plugin - You can now ban specific users from using the bot
+) New default plugin - Honourable user (bot admin) manager.

*) Fixed plugin: Deadbox check. The plugin never properly set the time of the last message, so it never worked.
*) Fixed plugin: LastSeen should now properly greet specific users if they haven't posted for ~24hrs
*) There is now a function that allows you to get the current UNIX time. It's in the settings class.
*) Release.zip should now be extractable by all zip archivers, not just the very modern ones.
1 change: 1 addition & 0 deletions PluginSettings.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#Tue Oct 06 10:28:36 UTC 2015
LastSeen=
StreamerList=zingmars\:0\\0
HonourableUsers=
3 changes: 1 addition & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ There are couple of notes though:

------
# TODO?

A full refactor to make the code consistent would be nice. Plenty of TODO's scattered through the code as well. Even so, this is project is, for all intents and purposes, finished. Feel free to fork and do whatever.
A full refactor to make the code consistent would be nice. Some TODO's are listed in the TODO file as well. Even so, this is project is, for all intents and purposes, finished. Feel free to fork and do whatever.

------
# License
Expand Down
20 changes: 20 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Cbox class:
+) Have it check login state every couple of hours
*) Fix characters going missing when sending a message
*) Fix custom emotes being in <img> tags (have them appear as emote: <emotename>)
*) Since cbox automatically html encodes the messages, decode them back to their respective characters

CLI class:
*) All of the CLI commands should have some sort of result indicators
*) Fix CLI crashing on some exceptions, even if they are caught
*) Make CLI chat have output that is independent of input

Plugin loader class:
*) Find a way to make Class loader non-case sensitive

Plugins:
+) Write a plugin that allows managing the bot the same way you can do it from CLI. (Have them share the function sets?)
+) Finish the quotes plugin
*) Rewrite AdminCommands
*) Get a JSON parser library for LastSeen and TwitchCheck plugins, implement it
*) Implement a way for plugins to register their commands to avoid duplicate commands and allow easier @help output
5 changes: 3 additions & 2 deletions src/BasePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ThreadController
open public class BasePlugin() {
public var settings :Settings? = null
public var logger :Logger? = null
public var handher :Plugins? = null
public var handler :Plugins? = null
public var pluginName :String? = null
public var controller :ThreadController? = null

Expand All @@ -30,7 +30,7 @@ open public class BasePlugin() {
{
this.settings = settings
this.logger = logger
this.handher = pluginsHandler
this.handler = pluginsHandler
this.pluginName = pluginName
this.controller = controller
if(this.pubInit()) this.logger?.LogPlugin(pluginName, "Started!")
Expand All @@ -45,4 +45,5 @@ open public class BasePlugin() {
open public fun pubInit() :Boolean { return true } //Initializer
open public fun connector(buffer :PluginBufferItem) :Boolean { return true } //Receives data from Plugin controller
open public fun stop() {} //This is run when the plugin is unloaded
open public fun executeCommand(command :String) :String { return "Plugin not configured" } //Execute a command
}
78 changes: 78 additions & 0 deletions src/BotPlugins/AbuserList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Created by zingmars on 11.10.2015.
*/
package BotPlugins
import Containers.PluginBufferItem

public class AbuserList : BasePlugin()
{
override fun pubInit() :Boolean
{
return true
}
override fun connector(buffer : PluginBufferItem) :Boolean
{
var message = buffer.message.split(" ")
when(message[0].toLowerCase()) {
"@ignorelist" -> {
var ignored = settings?.GetSetting("AbuserList") as String
var isAdmin = handler?.isPluginAdmin(buffer.userName) as Boolean
if(message[1] != "") {
controller?.AddToBoxBuffer("Users banned from using the bot: " + ignored)
} else {
if (isAdmin) {
if(message[1] == "add") {
if(message[2] == "") {
controller?.AddToBoxBuffer("Please enter an username")
} else {
AddIgnored(message[2])
}
} else if (message[1] == "remove") {
if(message[2] == "") {
controller?.AddToBoxBuffer("Please enter an username")
} else {
if(!RemoveIgnored(message[2])) {
controller?.AddToBoxBuffer(message[2] + " is not in the ignored list.")
}
}
}
} else {
controller?.AddToBoxBuffer("Insufficient rights")
}
}
}
}
return true
}
override fun executeCommand(command :String) :String
{
var action = command.split(",")
when(action[0].toLowerCase()) {
"add" -> { return "Result: " + AddIgnored(action[1]).toString()}
"remove" -> { return "Result: " + RemoveIgnored(action[1]).toString() }
else -> { return "Incorrect command"}
}
}

private fun AddIgnored(name :String) :Boolean
{
var ignorelist = settings?.GetSetting("AbuserList") as String
if(!ignorelist.contains(name)) {
settings?.SetSetting("AbuserList", ignorelist+","+name)
logger?.LogPlugin(this.pluginName as String, "User ignored: " + name)
return true
}
return false
}
private fun RemoveIgnored(name :String) :Boolean
{
var ignorelist = settings?.GetSetting("AbuserList") as String
if(ignorelist.contains(name)) {
ignorelist = ignorelist.substring(0, ignorelist.indexOf(name)-1) + ignorelist.substring(ignorelist.indexOf(name)+name.length())
settings?.SetSetting("AbuserList", ignorelist)
logger?.LogPlugin(this.pluginName as String, "Removed ignored user: " + name)
return true
}
return false
}
}
2 changes: 1 addition & 1 deletion src/BotPlugins/AdminCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AdminCommands : BasePlugin()
override fun pubInit() :Boolean
{
try {
if(handher?.isAdmin() == false) {
if(handler?.isAdmin() == false) {
throw Exception("User does not have mod rights to the given box. Exiting.")
}

Expand Down
26 changes: 16 additions & 10 deletions src/BotPlugins/DeadboxCheck.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ public class DeadboxCheck : BasePlugin()
}
override fun connector(buffer : PluginBufferItem) :Boolean
{
var timeSinceLast = buffer.time.toLong() - lastMessage
if(lastMessage != 0L && timeSinceLast >= 3600L) {
if(timeSinceLast > RecordTime) {
RecordTime = timeSinceLast
RecordUsername = buffer.userName
controller?.AddToBoxBuffer("Congratz " + buffer.userName + "! You just revived the box and set a new record doing so! This deadbox lasted " + (timeSinceLast.toDouble()/60).toString() + " minutes.")
saveData()
} else {
controller?.AddToBoxBuffer("Congratz " + buffer.userName + "! You just revived the box. This deadbox lasted " + (timeSinceLast.toDouble()/60).toString() + " minutes. The longest recorded deadbox was " + (RecordTime.toDouble()/60).toString() + " minutes long and it was broken by " + RecordUsername)
try {
var timeSinceLast = buffer.time.toLong() - lastMessage
if(lastMessage != 0L && timeSinceLast >= 3600L) {
if(timeSinceLast > RecordTime) {
RecordTime = timeSinceLast
RecordUsername = buffer.userName
controller?.AddToBoxBuffer("Congratz " + buffer.userName + "! You just revived the box and set a new record doing so! This deadbox lasted " + (timeSinceLast.toDouble()/60).toString() + " minutes.")
saveData()
} else {
controller?.AddToBoxBuffer("Congratz " + buffer.userName + "! You just revived the box. This deadbox lasted " + (timeSinceLast.toDouble()/60).toString() + " minutes. The longest recorded deadbox was " + (RecordTime.toDouble()/60).toString() + " minutes long and it was broken by " + RecordUsername)
}
}
lastMessage = settings?.getCurrentTime() as Long
return true
} catch (e: Exception) {
logger?.LogPlugin(this.pluginName as String, "Error: " + e.toString())
return false
}
return true
}
private fun saveData()
{
Expand Down
81 changes: 81 additions & 0 deletions src/BotPlugins/HonourableUsers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Allows adding bot admins
* Created by zingmars on 11.10.2015.
*/
package BotPlugins
import Containers.PluginBufferItem

public class HonourableUsers : BasePlugin()
{
override fun pubInit() :Boolean
{
return true
}
override fun connector(buffer : PluginBufferItem) :Boolean
{
var message = buffer.message.split(" ")
when(message[0].toLowerCase()) {
"@admins" -> {
var admins = settings?.GetSetting("HonourableUsers").toString()
var isAdmin = handler?.isPluginAdmin(buffer.userName) as Boolean
if(message[1] != "") {
controller?.AddToBoxBuffer("Bot administrators: " + admins)
} else {
if(isAdmin) {
if(message[1] == "add") {
if(message[2] == "") {
controller?.AddToBoxBuffer("Please enter username")
} else {
AddAdmin(message[2])
}
} else if (message[1] == "remove") {
if(message[2] == "") {
controller?.AddToBoxBuffer("Please enter username")
} else {
if(!RemoveAdmin(message[2])) {
controller?.AddToBoxBuffer(message[2]+" is not an admin.")
}
}
}
} else {
controller?.AddToBoxBuffer("Insufficient rights")
}
}
}
}
return true
}
override fun executeCommand(command :String) :String
{
var action = command.split(",")
when(action[0].toLowerCase()) {
"add" -> { return "Result: " + AddAdmin(action[1]).toString()}
"remove" -> { return "Result: " + RemoveAdmin(action[1]).toString() }
else -> { return "Incorrect command"}
}
}

// Admin management functions
private fun AddAdmin(name :String) :Boolean
{
var admins = settings?.GetSetting("HonourableUsers") as String
if(!admins.contains(name)) {
settings?.SetSetting("HonourableUsers", admins+","+name)
logger?.LogPlugin(this.pluginName as String, "Adding admin: " + name)
return true
}
return false
}
private fun RemoveAdmin(name :String) :Boolean
{
var admins = settings?.GetSetting("HonourableUsers") as String
if(admins.contains(name)) {
admins = admins.substring(0, admins.indexOf(name)-1) + admins.substring(admins.indexOf(name)+name.length())
settings?.SetSetting("HonourableUsers", admins)
logger?.LogPlugin(this.pluginName as String, "Removed admin: " + name)
return true
}
return false
}
}

11 changes: 3 additions & 8 deletions src/BotPlugins/LastSeen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.util.*

public class LastSeen : BasePlugin() {
var users :TreeMap<String, ArrayList<String>> = TreeMap(String.CASE_INSENSITIVE_ORDER)
var HonourableUsers = ArrayList<String>()
//TODO: Convert the data into a JSON string or something, because if someone uses these characters in their username the loading will be broken
var dbUserNameSeparator = "="
var dbUserDataSeparator = "+"
Expand Down Expand Up @@ -50,9 +49,7 @@ public class LastSeen : BasePlugin() {
//Load data saved in the database
try {
settings?.checkSetting("LastSeen", true) //Create the settings variable if it doesn't exist, otherwise it will return a fail
settings?.checkSetting("LastSeenHonourable", true)

var savedHonours = settings?.GetSetting("LastSeenHonourable")
var savedDB = settings?.GetSetting("LastSeen").toString()
if(savedDB != "") {
var data = savedDB.split(dbRecordSeparator)
Expand All @@ -62,9 +59,6 @@ public class LastSeen : BasePlugin() {
users.put(username, userdata)
}
}
if(savedHonours != "" && savedHonours != null) {
HonourableUsers = savedHonours.split(",").toArrayList()
}
//Run a separate thread to save users in the background
saverThread = Thread(Runnable { this.databaseSaver() })
saverThread.isDaemon = true
Expand All @@ -83,7 +77,7 @@ public class LastSeen : BasePlugin() {
if(message[0].toLowerCase() == "@lastseen" && (buffer.privilvl == "mod" || buffer.privilvl == "user")) {
var user = users.get(message[1])
if(user != null) {
if(message[1].toLowerCase() != handher?.username?.toLowerCase()) {
if(message[1].toLowerCase() != handler?.username?.toLowerCase()) {
controller?.AddToBoxBuffer(buffer.userName+": User \"" + message[1] + "\" last seen " + Date(user[2].toLong()*1000).toString())
} else {
controller?.AddToBoxBuffer(buffer.userName+": I'm here!")
Expand All @@ -97,7 +91,8 @@ public class LastSeen : BasePlugin() {
var user = users.get(buffer.userName)
if(user != null) {
// Greet Honourable users
if(HonourableUsers.contains(buffer.userName) && buffer.time.toLong() - user[2].toLong() > 86400) {
var isAdmin = handler?.isPluginAdmin(buffer.userName) as Boolean
if(isAdmin && buffer.time.toLong() - user[2].toLong() > 86400) {
controller?.AddToBoxBuffer("Welcome back " + buffer.userName + "!")
}

Expand Down
48 changes: 48 additions & 0 deletions src/BotPlugins/Quotes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Return a quote.
* Created by zingmars on 11.10.2015.
*/
package BotPlugins
import Containers.PluginBufferItem

public class Quotes : BasePlugin()
{
override fun pubInit() :Boolean
{
// Load quotes DB
return false // Not implemented yet
}
override fun connector(buffer : PluginBufferItem) :Boolean
{
var message = buffer.message.split(" ")
when(message[0].toLowerCase()) {
"@quote" -> {
var isAdmin = handler?.isPluginAdmin(buffer.userName) as Boolean
if(message[1] != "") {
// Select specific quote
} else {
if(isAdmin) {
if(message[1] == "add") {
// Add a quote. Check for privileges.
} else if(message[1] == "remove") {

}
else {
// Select a random quote
}
} else {

}
}
}
}
return true
}
override fun executeCommand(command :String) :String
{
// Reload quotes
// Add
// Remove
return ""
}
}
Loading

0 comments on commit 82faf2d

Please sign in to comment.