Code Monkey home page Code Monkey logo

Comments (10)

Meowhal avatar Meowhal commented on May 30, 2024 2

rewrite the line according to whether you want to use cli or discord.

let client = new irc.Client(c.server, c.nick, c.opt);

let ircClient = new irc.Client(c.server, c.nick, c.opt);

let ircClient = new irc.Client(c.server, c.nick, { port: 6667, password: "your password" });

or

c.opt.password = "your password";
let ircClient = new irc.Client(c.server, c.nick, c.opt);

from osu-ahr.

Meowhal avatar Meowhal commented on May 30, 2024 2

yep, but you can ignore trial files.
trial is used to check the behavior of the program and is not used in normal operation.

from osu-ahr.

SpicyDice avatar SpicyDice commented on May 30, 2024 1

thank you!
for discord token though I put my discord token directly here by replacing this.cfg.token

await this.discordClient.login(this.cfg.token);

- await this.discordClient.login(this.cfg.token); 
+ await this.discordClient.login('MyStringToken'); 

and here
https://github.com/Meowhal/osu-ahr/blob/199a661afc4938160b2fd9537e48d4fc87081e6d/src/trials/AppendersTrial.ts#L55

is that alright or can that be done better?

from osu-ahr.

ZeroPyrozen avatar ZeroPyrozen commented on May 30, 2024 1

for discord token though I put my discord token directly here by replacing this.cfg.token in between the ()

Just make sure to not share your discord token by pushing to your fork by adding it to .gitignore.

from osu-ahr.

ZeroPyrozen avatar ZeroPyrozen commented on May 30, 2024 1
c.opt.password = "your password";
let ircClient = new irc.Client(c.server, c.nick, c.opt);

using that ^, one gives an error. the first one works, i just tried this 2nd one and found out it doesn't work.

> [email protected] start:discord
> ts-node src/discord/index.ts

starting up...
[22:23:57.955][ERROR] cli - TypeError: Cannot assign to read only property 'password' of object '#<Object>'
    at Object.<anonymous> (/home/runner/ahr/src/discord/index.ts:29:19)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/home/runner/ahr/node_modules/ts-node/src/index.ts:1365:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/runner/ahr/node_modules/ts-node/src/index.ts:1368:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at main (/home/runner/ahr/node_modules/ts-node/src/bin.ts:331:12)
    at Object.<anonymous> (/home/runner/ahr/node_modules/ts-node/src/bin.ts:482:3)

IIrcConfig is interface not class so it need to be implemented before usage. Create IrcConfig and ClientOpts class first in TypedConfig.ts

export class ClientOpts implements IClientOpts {

}

export class IrcConfig implements IIrcConfig {
  server: string;
  nick: string;
  opt: IClientOpts;
  constructor(server: string, nick: string, opt: ClientOpts){
    this.server = server;
    this.nick = nick;
    this.opt = opt;
  }
}

then create the object in the index.ts

  var cOpt : ClientOpts =  {port: 6667,password: "yourPassword"};
  var c = new IrcConfig("irc.ppy.sh","YourNickname",cOpt);

from osu-ahr.

ZeroPyrozen avatar ZeroPyrozen commented on May 30, 2024 1

yes that's the one, var c that I mentioned above should be used with const c = getIrcConfig(); commented out

from osu-ahr.

SpicyDice avatar SpicyDice commented on May 30, 2024 1

oooh! so with that it's supposed to look like

import { Client, Intents } from "discord.js";
import log4js from "log4js";
import { DiscordBot } from './DiscordBot';
import { logIrcEvent } from "..";
import * as irc from '../libs/irc';
- import { getIrcConfig } from "../TypedConfig";
+ import { ClientOpts, IrcConfig } from "../TypedConfig";
import { logPrivateMessage } from '../IIrcClient';
import { applySpeedLimit } from "../libs/ChatLimiter";

const logger = log4js.getLogger("cli");

console.log("starting up...");

const config_path = "./config/log_discord.json";

try {
    log4js.configure(config_path);

-   const c = getIrcConfig();
+   var cOpt: ClientOpts =  {port: 6667,password: "yourPassword"};
+   var c = new IrcConfig("irc.ppy.sh","YourNickname",cOpt);
    if (c.nick == "your account id" || c.opt.password == "you can get password from 'https://osu.ppy.sh/p/irc'") {
        logger.error("you must enter your account name and irc password in the config file. ");
        logger.error("you can get the password from 'https://osu.ppy.sh/p/irc' ");
        logger.error("Copy config/default.json to config/local.json, and enter your id and irc password.");
        process.exit(1);
    }

    let ircClient = new irc.Client(c.server, c.nick, c.opt);
    ircClient.on("error", err => {
        if (err.command == "err_passwdmismatch") {
            logger.error('%s: %s', err.command, err.args.join(' '));
            logger.error("check your account id and password.");
            process.exit(1);
        }
    });
    applySpeedLimit(ircClient, 10, 5000);
    logIrcEvent(ircClient);
    logPrivateMessage(ircClient);

    let discordClient = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_INTEGRATIONS] });

    const bot = new DiscordBot(ircClient, discordClient);
    bot.start();
} catch (e: any) {
    logger.error(e);
    process.exit(1);
}

thank you so much for your time! have a good day, y'all amazing for making this awesome bot, looking forward towards its improvement!

from osu-ahr.

ZeroPyrozen avatar ZeroPyrozen commented on May 30, 2024 1

Just make sure that index.ts doesn't get commited to your public repository because your IRC credential is there now. You can create another index file like index-local.ts then on package.json change this line "start:discord": "ts-node src/discord/index.ts", to "start:discord": "ts-node src/discord/index-local.ts", then add the path to gitignore.

from osu-ahr.

SpicyDice avatar SpicyDice commented on May 30, 2024

or

c.opt.password = "your password";
let ircClient = new irc.Client(c.server, c.nick, c.opt);

the first implementation works. trying that second implementation however gives an error, i had just found out that the second implementation doesn't work.

> osu-ahr@1.5.13 start:discord
> ts-node src/discord/index.ts

starting up...
[22:23:57.955][ERROR] cli - TypeError: Cannot assign to read only property 'password' of object '#<Object>'
    at Object.<anonymous> (/home/runner/ahr/src/discord/index.ts:29:19)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/home/runner/ahr/node_modules/ts-node/src/index.ts:1365:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/home/runner/ahr/node_modules/ts-node/src/index.ts:1368:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at main (/home/runner/ahr/node_modules/ts-node/src/bin.ts:331:12)
    at Object.<anonymous> (/home/runner/ahr/node_modules/ts-node/src/bin.ts:482:3)

from osu-ahr.

SpicyDice avatar SpicyDice commented on May 30, 2024

IIrcConfig is interface not class so it need to be implemented before usage.

i did what you suggested on TypedConfig but
i was not sure where or how to put those var in src/discord/index.ts,
so here are the things i changed in src/discord/index.ts

const c = getIrcConfig();

    const c = getIrcConfig();
+   var cOpt: ClientOpts =  {port: 6667,password: "yourPassword"};
+   var c = new IrcConfig("irc.ppy.sh","YourNickname",cOpt);

i ran the bot.
i got a compilation error on console that ClientOpts and IrcConfig can't be found.

TSError: ⨯ Unable to compile TypeScript:
src/discord/index.ts:11:12 - error TS2304: Cannot find name 'ClientOpts'.
src/discord/index.ts:12:13 - error TS2304: Cannot find name 'IrcConfig'.

so...

import { getIrcConfig } from "../TypedConfig";

- import { getIrcConfig } from "../TypedConfig"; 
+ import { ClientOpts, IrcConfig } from "../TypedConfig";

I attempted to run it again with another error.

Cannot initialize outer scoped variable 'c' in the same scope as block scoped declaration 'c'.

so...

const c = getIrcConfig();

-   const c = getIrcConfig();
    var cOpt : ClientOpts =  {port: 6667,password: "yourPassword"};
    var c = new IrcConfig("irc.ppy.sh","YourNickname",cOpt);

i attempted to run it again. this time it worked.
did I do it right or did I do something wrong and it wasn't supposed to be done like that?

from osu-ahr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.