mirror of
https://github.com/PretendoNetwork/Yamamura.git
synced 2024-05-16 03:40:44 -04:00
Rewrite
Rewrote in Node and added slash commands
This commit is contained in:
parent
f134d72ad8
commit
deb6140594
0
.eslintignore
Normal file
0
.eslintignore
Normal file
43
.eslintrc.json
Normal file
43
.eslintrc.json
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"commonjs": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020
|
||||
},
|
||||
"globals": {
|
||||
"BigInt": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"rules": {
|
||||
"require-atomic-updates": "warn",
|
||||
"no-case-declarations": "off",
|
||||
"no-empty": "off",
|
||||
"no-console": "off",
|
||||
"linebreak-style": "off",
|
||||
"no-global-assign": "off",
|
||||
"prefer-const": "error",
|
||||
"no-var": "error",
|
||||
"one-var": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"indent": [
|
||||
"error",
|
||||
"tab",
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
]
|
||||
}
|
||||
}
|
65
.gitignore
vendored
65
.gitignore
vendored
|
@ -1,4 +1,61 @@
|
|||
config.json
|
||||
yamamura
|
||||
yamamura.log
|
||||
vendor/
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# custom
|
||||
config.json
|
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Yamamura
|
||||
Official community bot for the Pretendo Discord server
|
|
@ -1,8 +1,5 @@
|
|||
{
|
||||
"token" : "token goes here",
|
||||
"prefix" : ".",
|
||||
"moderators" : [ "moderator ids go here" ],
|
||||
"modmail_notif_optout" : [ ],
|
||||
"spam_channels" : [ "spam channel ids go here" ],
|
||||
"voting_channels": [ "voting channel ids go here" ]
|
||||
}
|
||||
"application_id": "",
|
||||
"public_key": "",
|
||||
"token": ""
|
||||
}
|
8
go.mod
8
go.mod
|
@ -1,8 +0,0 @@
|
|||
module github.com/superwhiskers/yamamura
|
||||
|
||||
require (
|
||||
github.com/bwmarrin/discordgo v0.19.0
|
||||
github.com/sirupsen/logrus v1.3.0
|
||||
github.com/superwhiskers/fennel v0.0.0-20190211044416-35119a6067a4
|
||||
github.com/superwhiskers/harmony v0.0.0-20180930143517-90dc7e62f9ee
|
||||
)
|
31
go.sum
31
go.sum
|
@ -1,31 +0,0 @@
|
|||
github.com/bwmarrin/discordgo v0.19.0 h1:kMED/DB0NR1QhRcalb85w0Cu3Ep2OrGAqZH1R5awQiY=
|
||||
github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/klauspost/compress v1.4.0 h1:8nsMz3tWa9SWWPL60G1V6CUsf4lLjWLTNEtibhe8gh8=
|
||||
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e h1:+lIPJOWl+jSiJOc70QXJ07+2eg2Jy2EC7Mi11BWujeM=
|
||||
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
|
||||
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/superwhiskers/fennel v0.0.0-20190211044416-35119a6067a4 h1:Hn/WZLe1retRbDrvj2g6K9pI449C2vpBJGhVgo89vWM=
|
||||
github.com/superwhiskers/fennel v0.0.0-20190211044416-35119a6067a4/go.mod h1:ysee5rymgTR5NGfYHbXsh0q69hRg1BIZoRZ9CtmkDaw=
|
||||
github.com/superwhiskers/harmony v0.0.0-20180930143517-90dc7e62f9ee h1:RnEP6ycC+YMfOnhfPd1BV0ihsycpPaKNrD9y3GFUk1Y=
|
||||
github.com/superwhiskers/harmony v0.0.0-20180930143517-90dc7e62f9ee/go.mod h1:lEkHPWe//0mZsMxYVhKB2LH/5U2dt+5JXmvlGXNzVF8=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.0.0 h1:BwIoZQbBsTo3v2F5lz5Oy3TlTq4wLKTLV260EVTEWco=
|
||||
github.com/valyala/fasthttp v1.0.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
|
||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
|
||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
@ -1,31 +0,0 @@
|
|||
subject=/C=US/ST=Washington/L=Redmond/O=Nintendo of America, Inc./OU=IS/CN=CTR Common Prod 1/emailAddress=ca@noa.nintendo.com
|
||||
issuer=/C=US/ST=Washington/O=Nintendo of America Inc./OU=IS/CN=Nintendo CA - G3
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEwzCCA6ugAwIBAgIBBjANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJVUzET
|
||||
MBEGA1UECBMKV2FzaGluZ3RvbjEhMB8GA1UEChMYTmludGVuZG8gb2YgQW1lcmlj
|
||||
YSBJbmMuMQswCQYDVQQLEwJJUzEZMBcGA1UEAxMQTmludGVuZG8gQ0EgLSBHMzAe
|
||||
Fw0xMDA1MTMxOTE5NDZaFw0zNzEyMjIxOTE5NDZaMIGlMQswCQYDVQQGEwJVUzET
|
||||
MBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9uZDEiMCAGA1UEChMZ
|
||||
TmludGVuZG8gb2YgQW1lcmljYSwgSW5jLjELMAkGA1UECxMCSVMxGjAYBgNVBAMT
|
||||
EUNUUiBDb21tb24gUHJvZCAxMSIwIAYJKoZIhvcNAQkBFhNjYUBub2EubmludGVu
|
||||
ZG8u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IJ
|
||||
yL1SiY7UmMlqQoGFV6IH4cwLiwm1wk/IF1tkfvR0gmECgYEA/vhTJYn/Gd3XY2tm
|
||||
vJs5pvmkJJgNxqgunOCFZxrGxf4BLvQGkRnBlT4MzFa1J8ZNtU6VOVbQsS7cD0ke
|
||||
2Kyv5rdt/7K2/bNdG4Ocnd+GcWpEtF+ik2wEQB48FQvYSQn/w5NKyJlyYOhXKGe3
|
||||
XhTiyV5rCwiLfRP8pxAO0xLzVhcCgYEA9FEX+hlxYdg2bVfx+geI9uW0COLi7kzc
|
||||
xxlPjBvdFltYsltSNLP+0BNqHfp3G5PW/XMTAdZnS9033gy4jLU6fAge8FcnLybh
|
||||
GrpVNCnMY+DLRyVtlu1fcKKH59BK/ElR7aamxqJyw1JO2Z35u251nIbmrMgs5Txp
|
||||
8aZ4HXCveHECgYEA1mRybddKhTKPwU53FdKkOK4jgo3Ez61tfIYiRl8ykxuRXSze
|
||||
NLZmm5qQYmXqb+aEQxcvzQYd907CxaujX2hdhG/q854P1uYyPUd+sxVYVBeaa90a
|
||||
tEGYlV2XAc9y73+T65z3vhOhJLFZUGVdv6NqSw60jZOCzwq2YLfU71E5AcMCgYEA
|
||||
jQ6c90rlSYaZtfvGu4LKMzJgBZlpSAicl18nrE8SEKxgw2kyRzd88QmkhPZs+kEb
|
||||
KW3dFXyCWyy36r4RdzvTLnVJ152aBAFAijv2oY1YcnoBI2yanz8hkVhlexOpl4uF
|
||||
f95t/9UeyWKmH8KzwuF9igfg+vT/5sJAsMJaKzU6OiECgYEAlKK+RKTYwquD+3gK
|
||||
o1gsGI+nR96Cb1kvfXzsj+V5UkZchew2pOqhrqpPknGIlFCeTDYjN8jqJyX4EljJ
|
||||
1FTegfhfSe+XR7KOIh8b+d+fgftyRIp3M//BUF1FtwL789f/VakaIkz6Ret/+8tA
|
||||
3UHqKKGtgSRL9kiTMVYy64pBG9A=
|
||||
-----END PRIVATE KEY-----
|
4279
package-lock.json
generated
Normal file
4279
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
24
package.json
Normal file
24
package.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "yamamura",
|
||||
"version": "1.0.0",
|
||||
"description": "Official community bot for the Pretendo Discord server",
|
||||
"main": "src/bot.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/PretendoNetwork/Yamamura.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/PretendoNetwork/Yamamura/issues"
|
||||
},
|
||||
"homepage": "https://github.com/PretendoNetwork/Yamamura#readme",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.3",
|
||||
"slash-create": "^3.0.1"
|
||||
}
|
||||
}
|
38
src/bot.js
Normal file
38
src/bot.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const { SlashCreator, GatewayServer } = require('slash-create');
|
||||
const Discord = require('discord.js');
|
||||
const config = require('../config.json');
|
||||
|
||||
const bot = new Discord.Client();
|
||||
const creator = new SlashCreator({
|
||||
applicationID: config.application_id,
|
||||
publicKey: config.public_key,
|
||||
token: config.token,
|
||||
});
|
||||
|
||||
const ToggleRoleCommand = require('./commands/toggleupdates');
|
||||
|
||||
creator
|
||||
.withServer(
|
||||
new GatewayServer(
|
||||
(handler) => bot.ws.on('INTERACTION_CREATE', handler)
|
||||
)
|
||||
)
|
||||
.registerCommands([
|
||||
new ToggleRoleCommand(bot, creator)
|
||||
])
|
||||
.syncCommands();
|
||||
|
||||
bot.on('message', message => {
|
||||
// Ignore bot messages
|
||||
if (message.author.bot) return;
|
||||
|
||||
// Check if the message is a command and handle it
|
||||
if (message.content === '.toggleupdates') {
|
||||
message.reply('Looks like you tried to use a legacy command! Try our new slash commands by just typing "/"!');
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
bot.login(config.token).then(() => {
|
||||
console.log('ready');
|
||||
});
|
62
src/commands/togglerole.js
Normal file
62
src/commands/togglerole.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
const { SlashCommand } = require('slash-create');
|
||||
|
||||
const allowedRoles = [
|
||||
{
|
||||
name: 'Updates',
|
||||
value: 'Updates'
|
||||
},
|
||||
{
|
||||
name: 'Stream Ping',
|
||||
value: 'StreamPing',
|
||||
}
|
||||
];
|
||||
|
||||
class ToggleRoleCommand extends SlashCommand {
|
||||
constructor(bot, creator) {
|
||||
super(creator, {
|
||||
name: 'togglerole',
|
||||
description: 'Toggle the provided role',
|
||||
options: [
|
||||
{
|
||||
name: 'role',
|
||||
description: 'Role name',
|
||||
required: true,
|
||||
type: 3,
|
||||
choices: allowedRoles
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.bot = bot;
|
||||
|
||||
this.filePath = __filename;
|
||||
}
|
||||
|
||||
async run(ctx) {
|
||||
const bot = this.bot;
|
||||
|
||||
const guild = await bot.guilds.fetch(ctx.data.guild_id, true);
|
||||
const user = await guild.members.fetch(ctx.data.member.user.id, true);
|
||||
const role = await guild.roles.cache.find(r => r.name === ctx.options.role);
|
||||
|
||||
if (!role) {
|
||||
return `Could not find role ${ctx.options.role}!`;
|
||||
}
|
||||
|
||||
const hasRole = await user.roles.cache.find(r => r.name === ctx.options.role);
|
||||
|
||||
if (hasRole) {
|
||||
await user.roles.remove(role);
|
||||
} else {
|
||||
await user.roles.add(role);
|
||||
}
|
||||
|
||||
return `Toggling role ${ctx.options.role} [${hasRole ? 'REMOVED' : 'ADDED'}]!`;
|
||||
}
|
||||
|
||||
onError(err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ToggleRoleCommand;
|
395
yamamura.go
395
yamamura.go
|
@ -1,395 +0,0 @@
|
|||
/*
|
||||
|
||||
yamamura - that one discord bot used in the pretendo discord server
|
||||
Copyright (C) 2018 superwhiskers <whiskerdev@protonmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/superwhiskers/harmony"
|
||||
"github.com/superwhiskers/fennel"
|
||||
)
|
||||
|
||||
type configType struct {
|
||||
Token string `json:"token"`
|
||||
Prefix string `json:"prefix"`
|
||||
Moderators []string `json:"moderators"`
|
||||
SpamChannels []string `json:"spam_channels"`
|
||||
VotingChannels []string `json:"voting_channels"`
|
||||
}
|
||||
|
||||
var (
|
||||
config configType
|
||||
handler *harmony.CommandHandler
|
||||
mentionRegex *regexp.Regexp
|
||||
ayyRegex *regexp.Regexp
|
||||
nintyClient *fennel.AccountServerClient
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
log.SetOutput(os.Stdout)
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
DisableColors: true,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
runtime.GOMAXPROCS(100)
|
||||
|
||||
logfile, err := os.OpenFile("yamamura.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
|
||||
log.Warnf("unable to open logfile. falling back to stdout only. error: %v", err)
|
||||
|
||||
} else {
|
||||
|
||||
defer logfile.Close()
|
||||
log.SetOutput(io.MultiWriter(os.Stdout, logfile))
|
||||
|
||||
}
|
||||
|
||||
configByte, err := ioutil.ReadFile("config.json")
|
||||
if err != nil {
|
||||
|
||||
log.Panicf("unable to read config file. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
err = json.Unmarshal(configByte, &config)
|
||||
if err != nil {
|
||||
|
||||
log.Panicf("unable to parse config file. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
var clientInfo = fennel.ClientInformation{
|
||||
ClientID: "ea25c66c26b403376b4c5ed94ab9cdea",
|
||||
ClientSecret: "d137be62cb6a2b831cad8c013b92fb55",
|
||||
DeviceCert: "",
|
||||
Environment: "",
|
||||
Country: "US",
|
||||
Region: "2",
|
||||
SysVersion: "1111",
|
||||
Serial: "1",
|
||||
DeviceID: "1",
|
||||
DeviceType: "",
|
||||
PlatformID: "1",
|
||||
}
|
||||
|
||||
nintyClient, err = fennel.NewAccountServerClient("https://account.pretendo.cc/v1/api", "keypair/ctr-common-cert.pem", "keypair/ctr-common-key.pem", clientInfo)
|
||||
if err != nil {
|
||||
|
||||
log.Panicf("unable to create fennel nintendo client. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
dg, err := discordgo.New(fmt.Sprintf("Bot %s", config.Token))
|
||||
if err != nil {
|
||||
|
||||
log.Panicf("unable to create a discordgo session object. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
mentionRegex = regexp.MustCompile("(?i)\\@everyone|(?i)\\@here")
|
||||
ayyRegex = regexp.MustCompile("(?i)\\bay{1,}\\b")
|
||||
|
||||
handler = harmony.New(config.Prefix, true)
|
||||
handler.OnMessageHandler = onMessage
|
||||
handler.AddCommand("help", false, help)
|
||||
handler.AddCommand("status", false, status)
|
||||
//handler.AddCommand("role", false, roleMeta)
|
||||
|
||||
dg.AddHandler(handler.OnMessage)
|
||||
dg.AddHandler(onReady)
|
||||
|
||||
err = dg.Open()
|
||||
if err != nil {
|
||||
|
||||
log.Panicf("unable to open the discord session. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
log.Printf("press ctrl-c to stop the bot...")
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
|
||||
<-sc
|
||||
|
||||
dg.Close()
|
||||
|
||||
}
|
||||
|
||||
// handles message create events
|
||||
func onMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
|
||||
if strings.HasPrefix(m.Content, config.Prefix) {
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
if m.Author.Bot == true {
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
member, err := s.GuildMember(m.GuildID, m.Author.ID)
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to get guild member. error: %v", err)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
content, err := m.ContentWithMoreMentionsReplaced(s)
|
||||
if err != nil {
|
||||
|
||||
content = m.ContentWithMentionsReplaced()
|
||||
|
||||
}
|
||||
|
||||
content = mentionRegex.ReplaceAllStringFunc(content, func(in string) string {
|
||||
|
||||
return strings.Join([]string{"<at>", in[1:]}, "")
|
||||
|
||||
})
|
||||
|
||||
if strings.ToLower(content) == "i'm a teapot" {
|
||||
|
||||
for _, roleID := range member.Roles {
|
||||
|
||||
if roleID == "415067373691863040" {
|
||||
|
||||
err = s.GuildMemberRoleRemove(m.GuildID, m.Author.ID, "415067373691863040")
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to remove role. error: %v", err)
|
||||
_, err = s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "error",
|
||||
Description: "sorry, but i was unable to remove your role",
|
||||
Color: 0xFFF176,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
_, err = s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "removed role",
|
||||
Description: "you no longer have the real devs role",
|
||||
Color: 0xFFF176,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err = s.GuildMemberRoleAdd(m.GuildID, m.Author.ID, "415067373691863040")
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to add role. error: %v", err)
|
||||
_, err = s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "error",
|
||||
Description: "sorry, but i was unable to add your role",
|
||||
Color: 0xFFF176,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
if ayyRegex.MatchString(content) {
|
||||
|
||||
lmao := ayyRegex.ReplaceAllStringFunc(content, func(in string) string {
|
||||
|
||||
lmao := strings.Replace(in[1:], "y", "o", -1)
|
||||
lmao = strings.Replace(lmao, "Y", "O", -1)
|
||||
if in[0] == []byte("a")[0] {
|
||||
|
||||
lmao = strings.Join([]string{"lma", lmao}, "")
|
||||
|
||||
} else {
|
||||
|
||||
lmao = strings.Join([]string{"LMA", lmao}, "")
|
||||
|
||||
}
|
||||
|
||||
return lmao
|
||||
|
||||
})
|
||||
|
||||
if len(lmao) > 2000 {
|
||||
|
||||
_, err := s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "error",
|
||||
Description: "sorry, but the resulting message was too long",
|
||||
Color: 0xFFF176,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
_, err = s.ChannelMessageSend(m.ChannelID, lmao)
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// handles the ready event
|
||||
func onReady(s *discordgo.Session, r *discordgo.Ready) {
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
log.Printf("logged in as %s on %d servers...", r.User.String(), len(r.Guilds))
|
||||
|
||||
}
|
||||
|
||||
// command that shows the help message
|
||||
func help(s *discordgo.Session, m *discordgo.MessageCreate, args []string) {
|
||||
|
||||
_, err := s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "yamamura",
|
||||
Description: "the official pretendo discord bot",
|
||||
Color: 0xFFF176,
|
||||
Fields: []*discordgo.MessageEmbedField{
|
||||
{
|
||||
Name: "commands",
|
||||
Value: `**help**: shows this message
|
||||
**status**: checks the status of the pretendo servers
|
||||
**role [toggle <name>|list]**: toggle a role or list the available roles to toggle`,
|
||||
Inline: false,
|
||||
},
|
||||
},
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
// server status command
|
||||
func status(s *discordgo.Session, m *discordgo.MessageCreate, args []string) {
|
||||
|
||||
_, _, err := nintyClient.GetEULA("US", "@latest")
|
||||
if err != nil {
|
||||
|
||||
// probably offline
|
||||
_, err := s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "server status",
|
||||
Description: "○ account.pretendo.cc",
|
||||
Color: 0xFFF176,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
_, err = s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
|
||||
Title: "server status",
|
||||
Description: "● account.pretendo.cc",
|
||||
Color: 0xFFF176,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "built with ❤ by superwhiskers#3210",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
log.Errorf("unable to send message. error: %v", err)
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue