Ver Fonte

Add random message react

horse há 4 anos atrás
pai
commit
4fadc50070

+ 31 - 0
bot/src/commands/random_react.ts

@@ -0,0 +1,31 @@
+import { CommandSet, Action, ActionType } from "src/model/command";
+import { Message } from "discord.js";
+import { getRepository } from "typeorm";
+import { RandomMessageReaction } from "@shared/db/entity/RandomMesssageReaction";
+import { client } from "src/client";
+
+@CommandSet
+export class RandomReact {
+    @Action(ActionType.MESSAGE)
+    async showHelp(actionsDone: boolean, msg: Message) {
+        if(actionsDone)
+            return false;
+
+        let repo = getRepository(RandomMessageReaction);
+
+        let reactInfo = await repo.findOne({ where: { userId: msg.author.id } });
+
+        if(!reactInfo)
+            return false;
+
+        let emote = client.emojis.get(reactInfo.reactionEmoteId);
+
+        if(!emote)
+            return false;
+
+        if(Math.random() < reactInfo.reactProbability)
+            await msg.react(emote);
+        
+        return false;
+    }
+}

+ 3 - 1
shared/src/db/entities.ts

@@ -13,6 +13,7 @@ import { Contest } from "./entity/Contest";
 import { ContestEntry } from "./entity/ContestEntry";
 import { ContestVote } from "./entity/ContestVote";
 import { FileOnlyChannel } from "./entity/FileOnlyChannel";
+import { RandomMessageReaction } from "./entity/RandomMesssageReaction";
 
 export const DB_ENTITIES = [
     AggroNewsItem,
@@ -32,5 +33,6 @@ export const DB_ENTITIES = [
     Contest,
     ContestEntry,
     ContestVote,
-    FileOnlyChannel
+    FileOnlyChannel,
+    RandomMessageReaction
 ];

+ 14 - 0
shared/src/db/entity/RandomMesssageReaction.ts

@@ -0,0 +1,14 @@
+import {Entity, PrimaryColumn, Column} from "typeorm";
+
+@Entity()
+export class RandomMessageReaction {
+    
+    @PrimaryColumn()
+    userId: string;
+
+    @Column()
+    reactionEmoteId: string;
+
+    @Column({ type: "decimal", default: 0.0 })
+    reactProbability: number;
+}