Skip to content

Commit

Permalink
Fixed array errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmars committed Oct 11, 2015
1 parent 82faf2d commit bf4e431
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 46 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
*) 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.
*) Release.zip should now be extractable by all zip archivers, not just the very modern ones.
(11.10.2015) v1.1.1
*) Fixed logic errors in the new plugins
9 changes: 5 additions & 4 deletions src/BotPlugins/AbuserList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ public class AbuserList : BasePlugin()
"@ignorelist" -> {
var ignored = settings?.GetSetting("AbuserList") as String
var isAdmin = handler?.isPluginAdmin(buffer.userName) as Boolean
if(message[1] != "") {
var commandSize = message.size()
if(commandSize == 1 || message[1] == "") {
controller?.AddToBoxBuffer("Users banned from using the bot: " + ignored)
} else {
} else if(commandSize > 1) {
if (isAdmin) {
if(message[1] == "add") {
if(message[2] == "") {
if(commandSize > 2 && message[2] == "") {
controller?.AddToBoxBuffer("Please enter an username")
} else {
AddIgnored(message[2])
}
} else if (message[1] == "remove") {
if(message[2] == "") {
if(commandSize > 2 && message[2] == "") {
controller?.AddToBoxBuffer("Please enter an username")
} else {
if(!RemoveIgnored(message[2])) {
Expand Down
13 changes: 7 additions & 6 deletions src/BotPlugins/HonourableUsers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ public class HonourableUsers : BasePlugin()
"@admins" -> {
var admins = settings?.GetSetting("HonourableUsers").toString()
var isAdmin = handler?.isPluginAdmin(buffer.userName) as Boolean
if(message[1] != "") {
var commandSize = message.size()
if(commandSize == 1 || message[1] == "") {
controller?.AddToBoxBuffer("Bot administrators: " + admins)
} else {
} else if(commandSize > 1) {
if(isAdmin) {
if(message[1] == "add") {
if(message[2] == "") {
controller?.AddToBoxBuffer("Please enter username")
} else {
if(commandSize > 2 && message[2] != "") {
AddAdmin(message[2])
} else {
controller?.AddToBoxBuffer("Please enter username")
}
} else if (message[1] == "remove") {
if(message[2] == "") {
if(commandSize > 2 && message[2] == "") {
controller?.AddToBoxBuffer("Please enter username")
} else {
if(!RemoveAdmin(message[2])) {
Expand Down
71 changes: 37 additions & 34 deletions src/BotPlugins/Time.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ public class Time : BasePlugin()
override fun connector(buffer : PluginBufferItem) :Boolean
{
var message = buffer.message.split(" ")
var commandSize = message.size()
when(message[0].toLowerCase()) {
"@time" -> {
var Format = SimpleDateFormat("dd-MM-yyyy HH:mm:ss z")
if(message[1] == "") {
if(commandSize == 1 || message[1] == "") {
controller?.AddToBoxBuffer("Current time: " + Format.format(Date()))
} else {
} else if(commandSize > 1) {
try {
var TZ = TimeZone.getTimeZone(message[1])
Format.timeZone = TZ
Expand All @@ -32,44 +33,46 @@ public class Time : BasePlugin()
}
}
"@timeuntil" -> {
var Format = SimpleDateFormat("dd-MM-yyyy HH:mm:ss")
try {
// 1 - Date
if(message[1] == "") {
throw Exception("Wrong date")
}
var date = message[1]
if(commandSize > 1) {
var Format = SimpleDateFormat("dd-MM-yyyy HH:mm:ss")
try {
// 1 - Date
if(message[1] == "") {
throw Exception("Wrong date")
}
var date = message[1]

// 2 - Hour
var hour = "00:00:00"
if(message[2] != "") {
hour = message[2]
}
// 2 - Hour
var hour = "00:00:00"
if(commandSize > 2 && message[2] != "") {
hour = message[2]
}

// 3 - Time zone
var timezone = "UTC"
if(message[3] != "") {
timezone = message[3]
}
// 3 - Time zone
var timezone = "UTC"
if(commandSize > 3 && message[3] != "") {
timezone = message[3]
}

var currentDate = Date()
var currentUNIX = currentDate.time/1000
var currentDate = Date()
var currentUNIX = currentDate.time/1000

var TZ = TimeZone.getTimeZone(timezone)
Format.timeZone = TZ
var inputTime = Format.parse(date + " " + hour)
var inputUNIX = inputTime.time/1000
var TZ = TimeZone.getTimeZone(timezone)
Format.timeZone = TZ
var inputTime = Format.parse(date + " " + hour)
var inputUNIX = inputTime.time/1000

var difference = inputUNIX - currentUNIX
if(difference < 1) {
controller?.AddToBoxBuffer(settings?.generateTimeString(currentUNIX, inputUNIX, "ago") as String)
}
else {
controller?.AddToBoxBuffer(settings?.generateTimeString(inputUNIX, currentUNIX, "") as String)
}
var difference = inputUNIX - currentUNIX
if(difference < 1) {
controller?.AddToBoxBuffer(settings?.generateTimeString(currentUNIX, inputUNIX, "ago") as String)
}
else {
controller?.AddToBoxBuffer(settings?.generateTimeString(inputUNIX, currentUNIX, "") as String)
}

} catch (e: Exception) {
controller?.AddToBoxBuffer("Syntax - dd-MM-yyyy HH:mm:ss z, where dd - date, MM - month, yyyy - year, HH - hour (24h), mm - minute, ss - second, z - timezone. You must specify a date, the rest is optional.")
} catch (e: Exception) {
controller?.AddToBoxBuffer("Syntax - dd-MM-yyyy HH:mm:ss z, where dd - date, MM - month, yyyy - year, HH - hour (24h), mm - minute, ss - second, z - timezone. You must specify a date, the rest is optional.")
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BotPlugins/UserCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UserCommands : BasePlugin()
"@help" -> {
controller?.AddToBoxBuffer("For more information please see https://github.com/zingmars/Cbox-bot. For feature requests ask zingmars.")
controller?.AddToBoxBuffer("@about - About this bot; @lastseen <username> - Output the date of user's last message; @ping - check if I'm alive; @help - display this; @time - time related commands (try help as a parameter")
controller?.AddToBoxBuffer("@laststream <username> - Get when an user has last streamed (try @laststream zingmars); @nextstream - OTG's next stream time; @quote - gets a random quote.")
controller?.AddToBoxBuffer("@laststream <username> - Get when an user has last streamed (try @laststream zingmars); @nextstream - OTG's next stream time")
controller?.AddToBoxBuffer("Available commands:")
}
"@about" -> {
Expand Down

0 comments on commit bf4e431

Please sign in to comment.