Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

brownie function! #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Ignore Gradle project-specific cache directory
.gradle

# shangs git ignore cause the doofus using intellij
.idea
# he also needs to remove the leaderboard he has locally stored
brownieLeaderboard.txt

# Ignore Gradle build output directory
build
8 changes: 8 additions & 0 deletions src/main/kotlin/co/netsoc/netsocbot/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ import co.netsoc.netsocbot.commands.registerDMs
import com.jessecorbett.diskord.util.*
import co.netsoc.netsocbot.utils.isDM
import java.net.UnknownHostException
import java.io.File

val BOT_TOKEN: String = System.getenv("NETSOCBOT_TOKEN")
val PREFIX = System.getenv("NETSOCBOT_PREFIX") ?: "!"
val ROLEIDS = (System.getenv("NETSOCBOT_ROLEIDS") ?: "").split(",")


suspend fun setup() {
val environmentVariables = arrayOf("NETSOCBOT_TOKEN", "NETSOCBOT_ROLEIDS", "NETSOCBOT_SENDGRID_TOKEN")
for (variable in environmentVariables) {
println(variable)
if (System.getenv(variable) == null) {
println("$variable not set\nExiting")
exitProcess(1)
}
}
var fileObject = File("brownieLeaderboard.txt")
Copy link
Member

Choose a reason for hiding this comment

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

text_file.exe OwO

Copy link
Contributor

Choose a reason for hiding this comment

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

I would use a dB instead of a file, simply a pair of user ID to amount of brownie points should be fine

if (!fileObject.exists()){
println("No leaderboard file")
fileObject.createNewFile()
}

}

Expand Down
44 changes: 43 additions & 1 deletion src/main/kotlin/co/netsoc/netsocbot/commands/CommandFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package co.netsoc.netsocbot.commands
import co.netsoc.netsocbot.*
import co.netsoc.netsocbot.utils.*
import com.jessecorbett.diskord.api.model.Message
import java.net.*
import java.io.File

fun help(message: Message): String {
var out = "```"
Expand All @@ -27,4 +27,46 @@ suspend fun register(message: Message): Unit {
}
messageUser(author, "Please message me your UCC email address so I can verify you as a member of UCC")
}
}

fun brownie(message: Message): String {
val receiver = message.usersMentioned.firstOrNull()
val author = message.author

// gonna use a file cause i dont know if im allowed to use a databse
var leaderboardFile = File("brownieLeaderboard.txt")
var yes = leaderboardFile.readLines()
Copy link
Contributor

Choose a reason for hiding this comment

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

Better variable names PLEASE

if (receiver != null && author.id != receiver.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a check to see that the author has not given someone else a brownie already today, could get quite spammy as it is now. This could be checked by simply storing author ID to the timestamp of the last time they gave a brownie point.

var fileOut = ""
var triggered = false

// checks file for the id of te user
for (id in yes) {
var id2 = id.split(" ")
var count = id2.elementAt(1).toInt()
if (id2.elementAt(0) == receiver.id){
count += 1
triggered = true
}
fileOut += id2.elementAt(0) + " " + count.toString() + "\n"
}

// this triggers if the users id isnt in the file and writes to anew line in the file
if (!triggered){
fileOut += receiver.id + " 1\n"
}
leaderboardFile.writeText(fileOut)

return receiver.username + " has been given a brownie point"
}
// this part triggers if someone hasnt been brownied and only calls the command brownie, they get to see their brownie score
var count = 0
for (id in yes) {
var id2 = id.split(" ")
if (id2.elementAt(0) == author.id){
count = id2.elementAt(1).toInt()
break
}
}
return author.username + " has " + count.toString() + " brownie points"
}
1 change: 1 addition & 0 deletions src/main/kotlin/co/netsoc/netsocbot/commands/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal fun register(command: String, helpString: String, action: (Message)->St
fun init(): HashMap<String, (Message)->String?> {
register("help", "Display this message", ::help)
register("ping", "Responds with a \"pong!\"", ::ping)
register("brownie", "Awards brownie points to the yser mentioned", ::brownie)

specialRegister("register", "Register as a UCC student for access to the server", ::register)

Expand Down