Giter Site home page Giter Site logo

teknologi-umum / bot Goto Github PK

View Code? Open in Web Editor NEW
22.0 22.0 22.0 2.7 MB

Bot for a more interactive Teknologi Umum group

Home Page: https://t.me/teknologi_umum

License: GNU General Public License v3.0

Shell 0.04% JavaScript 98.54% Handlebars 1.33% Dockerfile 0.08%
bot teknologi-umum telegram telegram-bot

bot's People

Contributors

aldy505 avatar arnoldart avatar artileda avatar bucol avatar dependabot[bot] avatar diosamuel avatar elianiva avatar farhan443 avatar ii64 avatar iiqbal2000 avatar krowter avatar lamualfa avatar nblfikr avatar ronnygunawan avatar valiangspe avatar vblinden avatar vmasdani avatar wahidinaji avatar yogipristiawan avatar zqwirp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bot's Issues

`/qr` <url>

/qr https://www.google.com/
  • Generate QR code (jangan pakai API)
  • Send QR code beserta linknya ke chat

An error was thrown when trying to delete a message on a private chat after calling the `/snap` command.

An error was thrown when trying to delete a message on a private chat after calling the /snap command.

Stack trace:

400: Bad Request: message can't be deleted for everyone

Crashed in non-app: /app/node_modules/telegraf/lib/core/network/client.js in Telegram.callApi
runMicrotasks
Called from: node:internal/process/task_queues in processTicksAndRejections
/app/src/services/snap/snap.js in async snap at line 37:7
Called from: /app/node_modules/telegraf/lib/composer.js in async execute

Error context:

key value
chat_type private
text /snap

/joke

Fetch https://jokesbapak2.herokuapp.com/v1/ then post the image

bug: Cannot read property 'type' of undefined

Sentry share URL: https://sentry.io/share/issue/c7e05989fcd1434abde8d9d6dea87058/ (see that link for the full stack trace of where the error came from)

Breadcrumbs:

http GET https://html.duckduckgo.com/html/?kp=1&q=apa+itu+lanlord [200] Info 09:44:09
http GET https://stackoverflow.com/questions/69413743/apa-itu-nonleaguezone-awa [301] Info 09:44:09
http GET https://stackoverflow.com/questions/69413743 [404] Info 09:44:09
exception TypeError: Cannot read property 'type' of undefined Error 09:44:09

Message text: /laodeai apa itu lanlord
The message was sent from a supergroup.

`/devread` command

Pingin bikin link ya isinya kumpulan renungan untuk kamerad TU sekalian.

Gimana menurut maintainer sekalian?

@aldy505

create `getCommandParameters` to unify the function to get command parameters.

Please let us know by commenting on this issue if you want to take this issue. Thanks!

Task

Create a getCommandParameters inside the /utils folder to simplify and unify the function to get the parameters for a command. Currently, it scatters here:

const re = new RegExp(`^/blidingej@${context.me}|/blidingej`);
const argument = context.message?.text?.replace(re, '').trim().toLowerCase() ?? '';

bot/src/services/blog.js

Lines 62 to 66 in 502177e

if (text.startsWith('/devread ')) {
kueri = text.substring(9);
} else if (text.startsWith(`/devread@${context.me} `)) {
kueri = text.substring(10 + context.me.length);
}

const re = new RegExp(`^/covid@${context.me}|/covid`);
const country = context.message?.text?.replace(re, '').trim().toLowerCase() ?? '';

if (text.startsWith('/eval ')) {
source = text.substring(6);
} else if (text.startsWith(`/eval@${context.me} `)) {
source = text.substring(7 + context.me.length);
} else if (text.startsWith('```') && text.endsWith('```')) {
source = text.substring(3, text.length - 4);

Resource

It is found that String.substring() is the fastest way to implement this. Try to put this JSBin code into JSBench. You'll find this result:

image


Tugas

Buat fungsi getCommandParameters di dalam folder /utils untuk menyederhanakan & menyatukan fungsi yang digunakan untuk ambil parameter dari command. Sekarang, fungsi-fungsi ini tersebar di:

const re = new RegExp(`^/blidingej@${context.me}|/blidingej`);
const argument = context.message?.text?.replace(re, '').trim().toLowerCase() ?? '';

bot/src/services/blog.js

Lines 62 to 66 in 502177e

if (text.startsWith('/devread ')) {
kueri = text.substring(9);
} else if (text.startsWith(`/devread@${context.me} `)) {
kueri = text.substring(10 + context.me.length);
}

const re = new RegExp(`^/covid@${context.me}|/covid`);
const country = context.message?.text?.replace(re, '').trim().toLowerCase() ?? '';

if (text.startsWith('/eval ')) {
source = text.substring(6);
} else if (text.startsWith(`/eval@${context.me} `)) {
source = text.substring(7 + context.me.length);
} else if (text.startsWith('```') && text.endsWith('```')) {
source = text.substring(3, text.length - 4);

Bahan pendukung

Sudah di benchmark dan ternyata String.substring() adalah cara tercepat dibandingkan 2 cara lain. Coba taruh kode JSBin ini ke JSBench. Kamu bakal nemuin hasil ini:

image

`/laodeai` handler: caniuse.com

use this as a test case: https://caniuse.com/css-grid

just add it into the handler lists, no need to think about how to call that handler. response might be only the supported device.

example response:

IE: partially supported
Edge: supported
Firefox: supported
Chrome: supported
Safari: supported
Opera: supported
Safari on iOS: supported
Opera Mini: not supported
Android Browser: supported
...

cc @elianiva

`/rosetta` Belajar koding lewat Bot

Ini ntar saya pikirin lagi.

Rencananya makan dari repo rosetta tapi perlu dibikin metadata khusus agar bisa memiliki bentukan data yang bisa dikonsumi oleh bot.

Give `/eval` superpowers

  • Evaluate exchange rates: #77
/eval 0.01 * $BTCUSDT

Output:
495.568
  • Evaluate stock prices: #71
/eval 100 * $BUKA

Output:
94500
  • Unit conversions
Spec to be discussed
  • Google knowledge graph
/eval Person("taylor swift").height

Output:
180

bug: Reduce of empty array with no initial value

Sentry share URL: https://sentry.io/share/issue/3a8fe798985e4a3f9e38606f485185fb/ (see this link for the stack trace of where the bug came from)

Breadcrumbs:

http GET https://html.duckduckgo.com/html/?kp=1&q=c%2B%2B+bool [200] Info 17:00:56
http GET https://stackoverflow.com/questions/1921539/using-boolean-values-in-c [200] Info 17:00:56
exception TypeError: Reduce of empty array with no initial value Error 17:00:56

Message text:
/laodeai c++ bool

From a supergroup.

regression: Promise timed out after 90000 milliseconds

Sentry share URL: https://sentry.io/share/issue/94706081554d48cd9d0613cb96437e7c/ (see that link for stack traces of where the bug came from)

Breadcrumbs:

http GET https://html.duckduckgo.com/html/?kp=1&q=rails+active+record+belongs_to+through [200] Info 16:43:32
http GET https://stackoverflow.com/questions/4021322/belongs-to-through-associations [200] Info 16:43:32
http POST https://teknologi-umum-graphene.fly.dev/api [[undefined]] Info 16:44:02
http POST https://teknologi-umum-graphene.fly.dev/api [[undefined]] Info 16:44:33
exception TimeoutError: Promise timed out after 90000 milliseconds Error 16:45:01

Message text: /laodeai rails active record belongs_to through
From a supergroup.

prepare for going public

karena bot ini OSS, agak serakah menurutku kalau we keep it to Teknologi Umum. udah lama kepikiran biar bot ini bisa dipake di grup lain.

tapi tentu saja, harus ada beberapa hal yang di adjust biar bot ini masih aman:

  • safe word list filter on /search command (#57 #55 #54 #52 #51)
  • disable /joke, /illuminati, /ynkts, /kktybs , /quote kalo member grup nya diatas 500 orang (#46)
  • set command /quiz, /blidingej exclusive ke grup teknologi umum (#46)
  • delete /time command (#46)
  • benerin konten dari /help biar lebih helpful (#61)
  • pin poll cuma bisa di grup teknologi umum (#46)
  • bikin documentation tentang cara tambahiin bot ke grup dan cara pake bot nya di repository ini (#53)
  • /kick and /ban command, along with /enable and /disable command (see #56)
  • implement statistics, jadi bisa tau bot ini ada di server mana aja (#70)

project issue ini lumayan jangka panjang, jangan di buru-buruin. kita semua punya kehidupan. mungkin kamu punya teman 2D yang harus diajak ngobrol.

`/devread typescript` returned error

Pas di test tembak ke API (https://api.pulo.dev/v1/contents?page=1&media=tulisan&query=typescript dan https://api.pulo.dev/v1/contents?page=1&media=web&query=typescript), masing-masing punya 1 result, jadi totalnya ada 3 result. Sedangkan bot ini ngirim 3 result seharusnya. Nah karena nggak ada result ke 3, jadinya null dan nggak bisa di parse via Array.map().

Masalahnya kemungkinan besar karena ini. Harus divalidasi kalo items.length < length dia bakal return items seadanya aja.

function randomArray(items, length) {
const shuffled = shuffle(items);
const result = [];
for (let i = 0; i < length; i++) {
const index = randomNumber(0, shuffled.length);
result.push(shuffled[index]);
}
return result;
}

Callernya disini:

const items = randomArray(data, 3);
const read = items.map(({ title, body, url }) => renderTemplate({ title, body, url })).join('\n');

cleaner safe `/search`

try to make the input and possible output as lowercase first, then test it against the data on mongodb to provide even cleaner safe search.

cc @elianiva

`/kick` and `/ban` command

usage:

  • group user (that must be an admin of that group) will reply to the message from the user that will be kicked or banned
  • can be enabled/disabled by a group admin with a specific command. might be /enable kick or /enable ban

rule sets:

  • should implement a voting system
  • if there is at least 15% of group admin that votes for a certain user, the user will be kicked/banned from the group
  • if 15% of group admin is less than 1, it will be rounded to its' higher number
  • if 15% of group admin is more than 1, it will be rounded to its' lower number
    • so a group with 3 admins will require 1 vote from an admin
    • a group with 30 admins will require 1 vote each from 4 admin

/eval

Sanitize javascript expression then return the output

`/laodeai` handler: linux man page

use this as a test case: https://www.man7.org/linux/man-pages/man0/stdio.h.0p.html

create a laodeai handler (https://github.com/teknologi-umum/bot/tree/master/src/services/laodeai/handlers) for that page. response/output might be:

stdio.h — standard buffered input/output

Some of the functionality described on this reference page
extends the ISO C standard. Applications shall define the
appropriate feature test macro (see the System Interfaces volume
of POSIX.1‐2017, Section 2.2, The Compilation Environment) to
enable the visibility of these symbols in this header.

The <stdio.h> header shall define the following data types
through typedef:

FILE          A structure containing information about a file.

fpos_t        A non-array type containing all information needed
             to specify uniquely every position within a file.

off_t         As described in <sys/types.h>.

size_t        As described in <stddef.h>.

ssize_t       As described in <sys/types.h>.

va_list       As described in <stdarg.h>.

The <stdio.h> header shall define the following macros which
shall expand to integer constant expressions:

BUFSIZ        Size of <stdio.h> buffers.  This shall expand to a
             positive value.

L_ctermid     Maximum size of character array to hold ctermid()
             output.

L_tmpnam      Maximum size of character array to hold tmpnam()
             output.

The <stdio.h> header shall define the following macros which
shall expand to integer constant expressions with distinct
values:

_IOFBF        Input/output fully buffered.

_IOLBF        Input/output line buffered.

_IONBF        Input/output unbuffered.

The <stdio.h> header shall define the following macros which
shall expand to integer constant expressions with distinct
values:

SEEK_CUR      Seek relative to current position.

SEEK_END      Seek relative to end-of-file.

SEEK_SET      Seek relative to start-of-file.

The <stdio.h> header shall define the following macros which
shall expand to integer constant expressions denoting
implementation limits:

{FILENAME_MAX}
             Maximum size in bytes of the longest pathname that
             the implementation guarantees can be opened.

{FOPEN_MAX}   Number of streams which the implementation
             guarantees can be open simultaneously. The value is
             at least eight.

{TMP_MAX}     Minimum number of unique filenames generated by
             tmpnam().  Maximum number of times an application
             can call tmpnam() reliably. The value of {TMP_MAX}
             is at least 25.

             On XSI-conformant systems, the value of {TMP_MAX}
             is at least 10000.

The <stdio.h> header shall define the following macro which shall
expand to an integer constant expression with type int and a
negative value:

EOF           End-of-file return value.

The <stdio.h> header shall define NULL as described in
<stddef.h>.

The <stdio.h> header shall define the following macro which shall
expand to a string constant:

P_tmpdir      Default directory prefix for tempnam().

The <stdio.h> header shall define the following macros which
shall expand to expressions of type ``pointer to FILE'' that
point to the FILE objects associated, respectively, with the
standard error, input, and output streams:

stderr        Standard error output stream.

stdin         Standard input stream.

stdout        Standard output stream.

The following shall be declared as functions and may also be
defined as macros. Function prototypes shall be provided.

   void     clearerr(FILE *);
   char    *ctermid(char *);
   int      dprintf(int, const char *restrict, ...)
   int      fclose(FILE *);
   FILE    *fdopen(int, const char *);
   int      feof(FILE *);
   int      ferror(FILE *);
   int      fflush(FILE *);
   int      fgetc(FILE *);
   int      fgetpos(FILE *restrict, fpos_t *restrict);
   char    *fgets(char *restrict, int, FILE *restrict);
   int      fileno(FILE *);
   void     flockfile(FILE *);
   FILE    *fmemopen(void *restrict, size_t, const char *restrict);
   FILE    *fopen(const char *restrict, const char *restrict);
   int      fprintf(FILE *restrict, const char *restrict, ...);
   int      fputc(int, FILE *);
   int      fputs(const char *restrict, FILE *restrict);
   size_t   fread(void *restrict, size_t, size_t, FILE *restrict);
   FILE    *freopen(const char *restrict, const char *restrict,
                FILE *restrict);
   int      fscanf(FILE *restrict, const char *restrict, ...);
   int      fseek(FILE *, long, int);
   int      fseeko(FILE *, off_t, int);
   int      fsetpos(FILE *, const fpos_t *);
   long     ftell(FILE *);
   off_t    ftello(FILE *);
   int      ftrylockfile(FILE *);
   void     funlockfile(FILE *);
   size_t   fwrite(const void *restrict, size_t, size_t, FILE *restrict);
   int      getc(FILE *);
   int      getchar(void);
   int      getc_unlocked(FILE *);
   int      getchar_unlocked(void);
   ssize_t  getdelim(char **restrict, size_t *restrict, int,
                FILE *restrict);
   ssize_t  getline(char **restrict, size_t *restrict, FILE *restrict);
   char    *gets(char *);
   FILE    *open_memstream(char **, size_t *);
   int      pclose(FILE *);
   void     perror(const char *);
   FILE    *popen(const char *, const char *);
   int      printf(const char *restrict, ...);
   int      putc(int, FILE *);
   int      putchar(int);
   int      putc_unlocked(int, FILE *);
   int      putchar_unlocked(int);
   int      puts(const char *);
   int      remove(const char *);
   int      rename(const char *, const char *);
   int      renameat(int, const char *, int, const char *);
   void     rewind(FILE *);
   int      scanf(const char *restrict, ...);
   void     setbuf(FILE *restrict, char *restrict);
   int      setvbuf(FILE *restrict, char *restrict, int, size_t);
   int      snprintf(char *restrict, size_t, const char *restrict, ...);
   int      sprintf(char *restrict, const char *restrict, ...);
   int      sscanf(const char *restrict, const char *restrict, ...);
   char    *tempnam(const char *, const char *);
   FILE    *tmpfile(void);
   char    *tmpnam(char *);
   int      ungetc(int, FILE *);
   int      vdprintf(int, const char *restrict, va_list);
   int      vfprintf(FILE *restrict, const char *restrict, va_list);
   int      vfscanf(FILE *restrict, const char *restrict, va_list);
   int      vprintf(const char *restrict, va_list);
   int      vscanf(const char *restrict, va_list);
   int      vsnprintf(char *restrict, size_t, const char *restrict,
                va_list);
   int      vsprintf(char *restrict, const char *restrict, va_list);
   int      vsscanf(const char *restrict, const char *restrict, va_list);

Inclusion of the <stdio.h> header may also make visible all
symbols from <stddef.h>.

The following sections are informative.

/covid

/covid - info covid seluruh dunia dan indonesia
/covid <nama_negara> - info covid di negara tertentu

bug: Error: can't parse entities

Link to Sentry issues:

Occurred when doing these on a public supergroup:

  • /laodeai the art of productive laziness
  • /search chrome download via blob

A bit of help:

http      GET    https://en.wikipedia.org/wiki/Laziness [200] info 05:59:21
http      POST   https://api.telegram.org/-redacted-/sendMessage [400] info 05:59:21
exception Error: 400: Bad Request: can't parse entities: Unmatched end tag at byte offset 490, expected "</i>", found "</a>" error 05:59:21
http      GET    https://html.duckduckgo.com/html/?kp=1&q=chrome+download+via+blob [200] info 08:15:39
http      POST   https://api.telegram.org/-redacted-/sendMessage [400] info 08:15:39
exception Error: 400: Bad Request: can't parse entities: Unsupported start tag "script" at byte offset 1893 error 08:15:39

If you need more information, feel free to ask it here or in the Telegram group. Good luck.

/carbon

Kirim di private chat:

/carbon function foo() {
  console.log("hello world")
}

Bot akan bikinin carbon

`/laodeai` handler: similarweb

/laodeai similarweb google.com

Show:

  • Global rank
  • Country rank (+ country & country flag)
  • Category rank (+ category name)
  • Total visits
  • Avg visit duration
  • Pages per visit
  • Bounce rate
  • Top 5 visitor's countries
  • Traffic sources
  • Top 10 competitors

captcha on user join

mungkin akan lebih baik kalo spesial hanya untuk grup teknologi umum. isi captchanya ya gausah random angka, tapi pertanyaan yang only human can answer with one word

  • kalo asu bahasa jawa, terjemahan indonesianya apa? "anjing"
  • kertas warnanya putih, awan warnanya putih, tissue warnanya putih. sapi minum apa? "air" / "air putih"
  • hal-hal mirip kayak gitu.

kalo ga bales dalam 3 menit, kick. kalo jawab selain jawaban bener, kick.

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.