Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Add Custom Telegram filter
Browse files Browse the repository at this point in the history
  • Loading branch information
valamidev committed Nov 8, 2021
1 parent a80e991 commit c601417
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ <h5 class="modal-title" id="settingModalLabel">Settings</h5>
<label for="settingTelegramChannel" class="form-label">TelegramChannelName</label>
<input type="text" class="form-control" id="settingTelegramChannel">
</div>
<div class="mb-3">
<label for="settingTelegramFilter" class="form-label">CustomFilterWord</label>
<input type="text" placeholder="BNB" class="form-control" id="settingTelegramFilter">
</div>
<div class="mb-3">
<label for="settingTelegramAPI" class="form-label">TelegramAPI ID</label>
<input type="text" class="form-control" id="settingTelegramAPI">
Expand Down
7 changes: 7 additions & 0 deletions assets/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ window.onload = (event) => {
if (store.has('telegramAPI')) {
document.getElementById('settingTelegramAPI').value = store.get('telegramAPI');
}
if (store.has('telegramFilter')) {
document.getElementById('settingTelegramFilter').value = store.get('telegramFilter');
}
if (store.has('telegramAPIHASH')) {
document.getElementById('settingTelegramAPIHASH').value = store.get('telegramAPIHASH');
}
Expand Down Expand Up @@ -157,6 +160,9 @@ const readSetting = () => {
const telegramChannel = document.getElementById('settingTelegramChannel').value;
const telegramAPI = document.getElementById('settingTelegramAPI').value;
const telegramAPIHASH = document.getElementById('settingTelegramAPIHASH').value;
const telegramFilter = document.getElementById('settingTelegramFilter').value;



const coinmarketcapAPI = document.getElementById('coinmarketcapAPI').value;

Expand All @@ -175,6 +181,7 @@ const readSetting = () => {
store.set('telegramAPI', telegramAPI.trim());
store.set('telegramAPIHASH', telegramAPIHASH.trim());
store.set('telegramSession', telegramSession.trim());
store.set('telegramFilter', telegramFilter.trim());
}


Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ const start = async (broker: ElectronBroker) => {
hash: store.get('telegramAPIHASH'),
session: store.get('telegramSession'),
channel: store.get('telegramChannel'),
filter: store.get('telegramFilter') || '',
};

const telegramSignaler = new TelegramScrapper(tgOption.api, tgOption.hash, tgOption.session, tgOption.channel);
const telegramSignaler = new TelegramScrapper(tgOption.api, tgOption.hash, tgOption.session, tgOption.channel, tgOption.filter);
telegramSignaler.on('newSignal', async (address: string) => {
try {
if (store.has('signalHistoryTg')) {
Expand Down
23 changes: 22 additions & 1 deletion src/plugins/telegram/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export class TelegramScrapper extends EventEmitter {
private listener?: NodeJS.Timer;
private client?: TelegramClient;

private customFilter?: string;

private lastProcessed = 0;

constructor(apiId: string, apiHash: string, session: string, channelName: string) {
constructor(apiId: string, apiHash: string, session: string, channelName: string, customFilter?: string) {
super();
this.apiId = Number(apiId);
this.apiHash = apiHash;
Expand Down Expand Up @@ -109,6 +111,25 @@ export class TelegramScrapper extends EventEmitter {
break;
}

// Custom Signal Filter
if(this?.customFilter && this?.customFilter !== "") {
if (content && content.includes(this.customFilter)) {

Logger.log('Telegram address found!', content, new Date());

const regex = /0x[a-fA-F0-9]{40}/;
const almostAddress = content.match(regex);

if (almostAddress[0] && this.lastSignal !== almostAddress[0]) {
this.lastSignal = almostAddress[0];
this.emit('newSignal', almostAddress[0]);
return;
}
}

return;
}

// CMC list signals
if (content && content.includes('first pump') && content.includes('BNB')) {

Expand Down

0 comments on commit c601417

Please sign in to comment.