ソースを参照

- Corrected some language mistakes

Parad0x 6 年 前
コミット
666f641aa4
8 ファイル変更29 行追加29 行削除
  1. 8 8
      README.md
  2. 4 5
      src/bot/app.ts
  3. 5 5
      src/bot/auth.ts
  4. 0 0
      src/commandRegister.ts
  5. 3 3
      src/connectionHandler.ts
  6. 4 3
      src/db/User.ts
  7. 4 4
      src/index.ts
  8. 1 1
      src/telegraf.ts

+ 8 - 8
README.md

@@ -2,24 +2,24 @@
 
 Simple communication bridge between clients and telegram. Using sockets is simple way for other clients to send notification. Current version support only one way communication (from client to telegram) but it should be possible to implement registering command. Protocol is based on queue where elements are separated with semicolons. 
 
-## Protocol's Operators
+## Protocol Operations
 
-### register
+### register (name)
 Reply with "\<id\>&\<auth\>"
 
 ```
-register;
+register;Test App;
 ```
 
 ### login (authcode)
-Reply with OK on success or ERR with message;
+Reply with "OK" on success or "ERR" with message;
 ```
 login;PIZS-4681-bKUp-2154;
 ```
 
 ### notify (msg)
 Need authentication
-Reply with OK on success or ERR with message;
+Reply with "OK" on success or "ERR" with message;
 ```
 notify; test notification;
 ```
@@ -31,14 +31,14 @@ ping;
 ```
 
 ### close
-Reply with closing message and close server connection
+Reply with closing message and close connection
 ```
 close;
 ```
 
-## Sample Comunication
+## Communication Sample
 ```
-Server in: register;close;
+Server in: register;Test App;close;
 Server out: 5&GSFBT-665-oJDDKqerYCWwfmtFWOOD;
 ```
 

+ 4 - 5
src/bot/app.ts

@@ -1,9 +1,8 @@
-import moment from "moment";
 import _debug from "debug";
 import {Markup, CallbackButton} from "telegraf";
 const debug = _debug("totify:bot/app");
 
-import cmdRegistry from "../commandRegistry";
+import cmdRegister from "../commandRegister";
 import telegraf from "../telegraf";
 import db from "../db";
 import _ie from "../utils/internalError";
@@ -95,7 +94,7 @@ function app() {
   });
 
   // List not activated apps
-  cmdRegistry.register("pendingApps", async (ctx) => {
+  cmdRegister.register("pendingApps", async (ctx) => {
     try {
       let pendingApps = await fetchPendingApps();
       if (pendingApps.length <= 0) {
@@ -110,7 +109,7 @@ function app() {
 
   // Register an App with name passed by argument
   // Return Name and authcode of new app instance
-  cmdRegistry.register("registerApp", async (ctx: Context) => {
+  cmdRegister.register("registerApp", async (ctx: Context) => {
     try {
       if(!ctx.state){
         throw new Error("There is no state attribute");
@@ -170,7 +169,7 @@ function app() {
   }
 
   // Return list of apps
-  cmdRegistry.register("apps", async (ctx: Context) => {
+  cmdRegister.register("apps", async (ctx: Context) => {
     try {
       if(!ctx.state){
         throw new Error("There is no state attribute");

+ 5 - 5
src/bot/auth.ts

@@ -1,4 +1,4 @@
-import cmdRegistry from "../commandRegistry";
+import cmdRegister from "../commandRegister";
 import telegraf from "../telegraf";
 import db from "../db";
 import authCode from "../authCode";
@@ -40,7 +40,7 @@ function auth(): void {
       });
 
       if (!!ctx.user) {
-        if (ctx.user.permanentBan || ctx.user.activated === false) {
+        if (ctx.user.permanentBan || ctx.user.isAuthenticated === false) {
           return;
         }
       }
@@ -51,12 +51,12 @@ function auth(): void {
   });
 
   // Authenticate with code from authCode file
-  cmdRegistry.register("auth", async (ctx: Context, next) => {
+  cmdRegister.register("auth", async (ctx: Context, next) => {
     try {
       if (!ctx.from || !ctx.state) {
         throw new Error("There is no from attribute");
       }
-      if (ctx.user && ctx.user.activated == true) {
+      if (ctx.user && ctx.user.isAuthenticated == true) {
         ctx.reply("Already authorised");
         return
       }
@@ -104,7 +104,7 @@ function auth(): void {
   })
 
   // Get current authCode
-  cmdRegistry.register("getAuthCode", (ctx) => {
+  cmdRegister.register("getAuthCode", (ctx) => {
     try {
       ctx.reply(`Actual authentication code: ${authCode.get()}`);
     } catch (e) {

+ 0 - 0
src/commandRegistry.ts → src/commandRegister.ts


+ 3 - 3
src/connectionHandler.ts

@@ -106,16 +106,16 @@ class Connection {
 
   
   /**
-   * Execute operator by running corresponding method of Connection
+   * Execute operation by running corresponding method of Connection
    *
-   * @param {string} op - operator
+   * @param {string} op - operation
    * @memberof Connection
    */
   async execute(op: string) {
     if (secureOp.includes(op)) {
       await this[<secureOp>op]();
     } else {
-      this.write("Unkown operator\n\r");
+      this.write("Unkown operation\n\r");
     }
 
   }

+ 4 - 3
src/db/User.ts

@@ -3,7 +3,7 @@ import Sequelize, { Model } from "sequelize";
 
 class User extends Model {
   userTelegramId!: number;
-  activated!: boolean;
+  isAuthenticated!: boolean;
   permanentBan!: boolean;
   
   public readonly updatedAt!: Date;
@@ -14,9 +14,10 @@ User.init({
   userTelegramId: {
     type: Sequelize.BIGINT
   },
-  activated: {
+  isAuthenticated: {
     type: Sequelize.BOOLEAN,
-    defaultValue: false
+    defaultValue: false,
+    field: "activated"
   },
   permanentBan: {
     type: Sequelize.BOOLEAN,

+ 4 - 4
src/index.ts

@@ -9,22 +9,22 @@ import chalk from "chalk";
 import _debug from "debug";
 const debug = _debug("totify:main");
 
-import socketPathCon from "./utils/socketPath";
+import getSocketPath from "./utils/socketPath";
 import connectionHandler from "./connectionHandler";
 import init from "./init";
 import prepareBot from "./bot";
 
 const server = net.createServer(connectionHandler);
 
-const socketPath = socketPathCon(process.env.TOTIFY_INSTANCENAME);
+const socketPath = getSocketPath(process.env.TOTIFY_INSTANCENAME);
 
 //Main
 
 (async () => {
 
-  debug("Starting awaited init");
+  debug("Initializing");
   await init();
-  debug("Initializing done")
+  debug("Initialization done")
 
   debug("Preparing bot");
   prepareBot();

+ 1 - 1
src/telegraf.ts

@@ -28,7 +28,7 @@ const telegraf: {
    */
   async send(message: string): Promise<void> {
     if(!this.bot){
-      throw new Error("Can't send when telegraf is not initialized");
+      throw new Error("Can't send message if telegraf is not initialized");
     }
     let chats = await this.chats();
     for (let id of chats) {