The following is a python based bot designed to help the UNSW OPSOC discord sever generate engagement and allow for members to get additional information about the OP universe.
When designing the bot the following was considered.
- Able to be run through an always-online server running docker
- Low maintenance
- Low processing power and networking bandwidth
- Help page with up-to-date spec
- Random image generator (inc data)
- Bot stats
- Guess the character game
- User profile
- Auto verification tagger
- Manual verification bypass
- Verification logs + timestamps
- RPG-style character collector
- Search character feature
-
If API keys or config file does not exist create a new file named
config.ini
and insert the following[keys] DiscordAPI-Key=XXXX.XXXX.XXXX [verification] webhookCommand=Command! webhookBotID=1234567890 targetChannelID=1234567890 unverifiedRole=role1 verifiedRole=role2 errorStateChannel=1234567890 [adminstration] level1OverRide=1234567890 level2OverRideRole=role3 [testing] isproduction=false disableAdmin=false DisableMultiplayer=false
-
Start an instance of Docker
-
Build script using docker
docker build -t dockerfile .
-
Run a script from Docker command
docker run -dp dockerfile
There is a comprehensive verification log with time stamps in the "admin.log" file, and "rpgData.log" is a secondary log for user info.
To implement verification with google forms a webhook is used to read received messages. You can implement the code linked to a Google form here.
- https://script.google.com/
- The corresponding setting used should be:
const POST_URL = {Webhook URL};
function onSubmit(e) {
Utilities.sleep(30000);
const response = e.response.getItemResponses();
let items = [];
let username = "";
for (const responseAnswer of response) {
const question = responseAnswer.getItem().getTitle();
const answer = responseAnswer.getResponse();
let parts = []
try {
parts = answer.match(/[\s\S]{1,1024}/g) || [];
} catch (e) {
parts = answer;
}
for (const [index, part] of Object.entries(parts)) {
if (question == "Discord Tag (e.g. abcde#1234)") {
username = part;
}
}
}
const options = {
"method": "post",
"headers": {
"Content-Type": "application/json",
},
"payload": JSON.stringify({
"content": "Auth!verifyUserWebServer1.1 " + username
})
};
UrlFetchApp.fetch(POST_URL, options);
};
-
Generate Python module requirements with
pipreqs ./ --force