trojanerhd / trojanerbot Goto Github PK
View Code? Open in Web Editor NEWMy discord bot
License: MIT License
My discord bot
License: MIT License
Since you can not only play games on Twitch (like “Art”, “Programming and Software Development”), it's wrong to say a streamer is playing a certain category. I'd suggest to fall back to “streamer x is streaming category y”
Currently, only if the streamer had no subscriptions before (meaning, they don't exist in the settings.json
), a message gets sent when subscribing while the streamer is live. This should be changed to always send a message when subscribing to somebody who is live right now
Currently, thanks to the Twitch API, only the first 20 streamers are returned in every request. This can be changed to 100 by specifying a first
field. If there are more than 100, the remaining streamers have to be obtained by separate requests with an after
field in the request using so-called pagnation
Currently, the bot - for whatever reason - sends the response See embed
and a separate embed message. This can be improved to only send the embed in the response
This possibly occurs due to asynchronous functions
Currently, the DM message only shows the category that was streamed when the streamer went live (or rather when the notification was sent). This should be changed to automatically update the message to the according game.
Randomly occurs after some time when starting the bot (in this case it took a few hours/days)
Probably some error handling is required in general
FetchError: invalid json response body at https://api.twitch.tv/helix/streams?user_login=<username>&user_login=<other username>&… reason: Unexpected token c in JSON at position 0
at /home/trojaner/Code/Web/TrojanerBot/node_modules/node-fetch/lib/index.js:272:32
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:93:5) {
type: 'invalid-json'
}
/home/trojaner/Code/Web/TrojanerBot/node_modules/node-fetch/lib/index.js:272
return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
^
FetchError: invalid json response body at https://api.twitch.tv/helix/games? reason: Unexpected token c in JSON at position 0
at /home/trojaner/Code/Web/TrojanerBot/node_modules/node-fetch/lib/index.js:272:32
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:93:5) {
type: 'invalid-json'
}
TrojanerBot/src/twitch/TwitchHelper.ts
Lines 41 to 45 in 4174061
This can be shortened
Features:
Yarn 3 has general improvements so one could update to it
When I started writing this bot, I didn't know that Array.prototype.some()
exists and used a workaround:
const found: T | undefined = array.find((elem: T): boolean => elem === something);
if (!found) console.log(false);
else console.log(true);
this can be changed to
const found: boolean = array.some((elem: T): boolean => elem === something);
console.log(found);
(In this case even to console.log(array.some((elem: T): boolean => elem === something));
)
this bot be really big crap. its nah worth anythin'. pls use HTTP://rs.defyu.se
Discord changed in an update that bot tokens can't change command permissions so now the following steps are required to automatically set permissions:
http://localhost:<PORT>
to https://discord.com/developers/applications/<CLIENT_ID>/oauth2/general
https://discord.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=applications.commands.permissions.update&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A<PORT>
PUT
request to Discord endpoint /applications/<APPLICATION_ID>/guilds/<GUILD_ID>/commands/<COMMAND_ID>/permissions
for each command with payload permissions: {id: string, type: 1 | 2 | 3, permission: boolean}[]
(See https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions for more information, specifically https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-structure for permission array)
<APPLICATION_ID>
can be globally received via DiscordClient._client.application?.id
Currently, the bot sends a notification every time the stream has been restarted (after five minutes of being live). It would be appropriate to add a flag last-live
or abuse the started-at
tag to store the time the streamer was last live. If that time is less than 10 minutes ago e. g. and the streamer goes live again, don't send a message again and instead start maintaining the old live messages again.
Followup to PR #67: If the bot will be used in multiple servers, it would be better if the admins of that server could configure the bot's settings directly through a /settings
command instead of the settings being sprayed into multiple /
commands as it is in the current implementation of that PR.
Setting would be:
/to
commandCurrently you can subscribe to channels but it does not send a DM. That needs to be implemented
Error: WebSocket was closed before the connection was established
at WebSocket.close (/home/trojaner/Code/Web/TrojanerBot/node_modules/ws/lib/websocket.j
s:285:14)
at WebSocketShard.destroy (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/
src/client/websocket/WebSocketShard.js:728:27)
at Timeout.<anonymous> (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src
/client/websocket/WebSocketShard.js:522:12)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (/home/trojaner/Code/Web/TrojanerBot/node_modules/ws/lib/websocket
.js:984:13)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Possibly bumping the discord.js version might fix that?
In the future, the bot should work with GitHub releases and warn the user when it is out of date with instructions to update. The ideal approach for development would be to slowly migrate each update with breaking changes that require migrations - as we see it in the following lines right now, for example:
Lines 62 to 108 in 4174061
When using /deploy or typing !deploy (with permissions), the error Uncaught Error Error: listen EADDRINUSE: address already in use :::3000
is thrown.
Because a redeployment creates a new instance of Authentication, a new express app is created that tries to listen to the same port as the previous one
Make server static and check if it has a value when creating a new Authentication instance. If so, don't listen to the same port again.
Upon deleting the setting express-port
in settings.json
, the bot automatically overwrites the settings and adds the setting back
Lines 44 to 57 in 6d401e8
Set the express port to a non-positive value (like 0)
Followup to PR #67: Currently, commands like /roles list
display a very raw and ugly output. Change that into embeds
It's just wasted TS/JS potential to not use it, has no disadvantages and results in potentially cleaner code
This might resolve #59
The current permissions rely on hard coded role names (Moderator
and Owner
).
It would be better for the bot owner to change that (Linked to #4)
Despite me having permissions the bot forbids me to execute !bye
.env
While the settings already uses a flag logging
for the log level, it is only used for logging initial information about whether the current bot's configuration is valid. However, I also want to use a logger in my code. That means, I want to be able to log anything anywhere under the condition that logging is set to at least level X.
Expected behavior:
Upon joining the channel “Talking”, a second channel gets generated and so forth.
Actual behavior
Upon joining the channel “Talking”, nothing happens at all.
When you download the source code you have to manually find out where to put the JSON files by running the bot, checking the error and creating a fitting JSON
Before:
for (let i: number = 0; i < array.length; ++i) {
const element = array[i];
console.log(element, 'has index', i);
}
After:
for (const [i, element] of array.entries()) console.log(element, 'has index', i);
Looks cleaner in my opinion
MIT?
Currently you have to add Twitch credentials even when you don't want to use this feature
Response: Internal Server Error
at RequestHandler.execute (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/rest/RequestHandler.js:161:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async RequestHandler.push (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
at async MessageManager._fetchMany (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/managers/MessageManager.js:140:18) {
code: 500,
method: 'get',
path: '/channels/630883093129199656/messages'
}
and
HTTPError [AbortError]: The user aborted a request.
at RequestHandler.execute (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/rest/RequestHandler.js:93:15)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async RequestHandler.push (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
at async MessageManager._fetchMany (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/managers/MessageManager.js:140:18) {
code: 500,
method: 'get',
path: '/channels/630883093129199656/messages'
}
occur sometimes.
Probably messages that are trying to be fetched and are getting deleted in the process(?)
The yarn.lock contains information with what version of the package the code works, hence it's important. Should be added to the repository
node:events:505
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT XXX.XXX.XXX.XXX:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'XXX.XXX.XXX.XXX',
port: 443
}
(IP replaced with XXX.XXX.XXX.XXX)
The functionality for the #live channel is broken. It displays a wrong refresh time and also doesn't show anything (sometimes?).
On that note, there should be an evaluation of the necessity of having this feature. Maybe just get rid of it?
TrojanerBot/src/messages/permissions/Authentication.ts
Lines 24 to 26 in 6d401e8
redirect_uri=<redirect_uri>
can be omittedHelp command is useless since discord has built-in descriptions and listings of slash commands
See
TrojanerBot/src/DiscordClient.ts
Lines 29 to 31 in 2a066ff
TrojanerBot/src/DiscordClient.ts
Line 37 in 2a066ff
Currently you have to create some JSON files scattered across the repository. It would be appropriate to centralize those JSON files e. g. in a folder or by merging them in total to one file
(Linked with #3)
/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/client/actions/InteractionCreate.js:48
if (channel && !channel.isText()) return;
^
TypeError: channel.isText is not a function
at InteractionCreateAction.handle (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/client/actions/InteractionCreate.js:48:33)
at Object.module.exports [as INTERACTION_CREATE] (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:346:31)
at WebSocketShard.onPacket (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:482:22)
at WebSocketShard.onMessage (/home/trojaner/Code/Web/TrojanerBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:317:10)
at callListener (/home/trojaner/Code/Web/TrojanerBot/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onMessage (/home/trojaner/Code/Web/TrojanerBot/node_modules/ws/lib/event-target.js:209:9)
at WebSocket.emit (node:events:513:28)
at Receiver.receiverOnMessage (/home/trojaner/Code/Web/TrojanerBot/node_modules/ws/lib/websocket.js:1180:20)
at Receiver.emit (node:events:513:28)
Currently, only custom emojis work for the roles channel since unicode emojis do not have an ID
Currently, settings.json
and .env
is for all servers at once, they won't get distinguished. Meaning, you can't show different streamers in different servers for example
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.