-
Notifications
You must be signed in to change notification settings - Fork 2
brownie function! #32
base: master
Are you sure you want to change the base?
Changes from all commits
66c6d0a
eea4ed5
b82bd47
7e3b121
0defa8a
0be17c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
} | ||
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = "```" | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better variable names PLEASE |
||
if (receiver != null && author.id != receiver.id) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text_file.exe OwO