forked from motoeng/koinbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telegrambot.py
505 lines (373 loc) ยท 16.3 KB
/
telegrambot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
import asyncio
from datetime import datetime, timedelta
from dotenv import load_dotenv
import os
import random
import requests
import signal
import telebot
from telebot.async_telebot import AsyncTeleBot
import time
load_dotenv()
bot = AsyncTeleBot(os.environ['TELEGRAM_BOT_TOKEN'])
chat_id = os.environ['CHAT_ID']
new_users = set()
new_users_lock = asyncio.Lock()
def get_programs():
url = 'https://koinos.io/api/programs'
response = requests.get(url)
data = response.json()
return data['programs']
def make_program_blurb(program):
return """โก๏ธ <b><a href="{url}">{title}</a></b>
๐ {subtitle}
{shortDescription}""".format_map(program)
async def send_message(message, link_preview=False, html=True, chat_id=chat_id, reply_markup=None):
return await bot.send_message(
chat_id,
message,
parse_mode='html' if html else None,
link_preview_options=telebot.types.LinkPreviewOptions(is_disabled=not link_preview),
reply_markup=reply_markup)
#welcome message
#@bot.message_handler(commands=['welcome'])
@bot.message_handler(content_types=['new_chat_members'])
async def handle_welcome(message):
await bot.delete_message(message.chat.id, message.id)
from_user = await bot.get_chat_member(message.chat.id, message.from_user.id)
# For testing using 'welcome'
if message.new_chat_members == None or len(message.new_chat_members) == 0:
message.new_chat_members = [message.from_user]
from_user.status = ""
if from_user.status == 'creator' or from_user.status == 'administrator':
await welcome_new_users(message.new_chat_members)
return
markup = telebot.types.ReplyKeyboardMarkup(one_time_keyboard=True, selective=True)
options = ['Koinos', 'Bitcoin', 'Chainge']
random.shuffle(options)
markup.add(*options)
captcha_messages = list()
async with new_users_lock:
for member in message.new_chat_members:
new_users.add(member.id)
captcha_messages.append(await send_message(f"Welcome @{member.username}, what is the name of this project?", reply_markup=markup))
await asyncio.sleep(180)
for captcha_message in captcha_messages:
try:
await bot.delete_message(captcha_message.chat.id, captcha_message.id)
except:
pass
async with new_users_lock:
for member in message.new_chat_members:
if {member.id} <= new_users:
new_users.remove(member.id)
await kick_user(member)
@bot.message_handler(func=lambda message: message.reply_to_message != None)
async def handle_new_user_response(message):
async with new_users_lock:
if not {message.from_user.id} <= new_users:
return
new_users.remove(message.from_user.id)
await bot.delete_message(message.chat.id, message.reply_to_message.id)
await bot.delete_message(message.chat.id, message.id)
if message.text != 'Koinos':
await kick_user(message.from_user)
return
await welcome_new_users([message.from_user])
async def kick_user(user):
await bot.kick_chat_member(chat_id, user.id, until_date=datetime.today() + timedelta(days=7) )
async def welcome_new_users(users):
programs = get_programs()
active_program_message = None
has_program_image = False
if len(programs) > 0:
for program in programs:
if not program['active']:
continue
active_program_message = f"""
๐ฎ Featured Program:
{make_program_blurb(program)}"""
if program['images'] != None and program['images']['banner'] != None:
has_program_image = True
active_program_message = f"""<a href="{program['images']['banner']}">‍</a>""" + active_program_message
response = ""
usernames =['@' + user.username for user in users]
if len(usernames) > 1:
usernames[-1] = 'and ' + usernames[-1]
username_list = ''
if len(usernames) > 2:
username_list = ', '.join(usernames)
else:
username_list = ' '.join(usernames)
response = f"""Welcome {username_list}!
To get started, we recommend you take a look at current /programs and take a moment to review the /rules.
Please feel free to ask questions!"""
if active_program_message != None:
response += active_program_message
response += """
๐จ Remember: Admins will never DM you first. They will never ask for your keys or seed phrase. \
If you suspect someone is impersonating an admin, please /report them.
"""
await send_message(response, link_preview=has_program_image, reply_markup=telebot.types.ReplyKeyboardRemove(selective=True))
@bot.message_handler(content_types=['left_chat_member'])
async def delete_leave_message(message):
await bot.delete_message(message.chat.id, message.id)
#list of commands
@bot.message_handler(commands=['help'])
async def send_help(message):
await send_message("""
You may use the following Commands:
/claim
/guides
/exchanges
/international
/price
/programs
/projects
/roadmap
/rules
/social
/stake
/supply
/vhpsupply
/wallets
/website
/whitepaper
""")
#report
@bot.message_handler(commands=['report'])
async def send_report(message):
await send_message("""
Admins, someone needs to be banned
@kuixihe @weleleliano @saleh_hawi @fifty2kph
""")
#website
@bot.message_handler(commands=['website', 'websites'])
async def send_website(message):
await send_message('<a href="https://koinos.io">Koinos Website</a>', True)
#stake
@bot.message_handler(commands=['stake'])
async def send_stake(message):
await send_message("""
๐ฅ Burn KOIN (similar to staking) for 1 year and earn 4-8% APR!
โ <a href="https://www.youtube.com/watch?v=v9bhaNLuDms">Koinos Overview: Miners, Holders, and Developers</a>
โ๏ธ <a href="https://youtu.be/pa2kSYSdVnE?si=kxX4BBbjriL29x6m">How to mine $KOIN with $VHP</a>
โจ๏ธ <a href="https://docs.koinos.io/validators/guides/running-a-node/">Run your own node</a>
<b>--or--</b>
๐ฅ Join a Pool!
<a href="https://fogata.io">Fogata</a>
<a href="https://burnkoin.com">Burn Koin</a>
""")
#whitepaper
@bot.message_handler(commands=['whitepaper'])
async def send_whitepaper(message):
await send_message("""
๐ <a href="https://koinos.io/whitepaper/">Official Whitepaper</a>
๐ค๏ธ <a href="https://podcast.thekoinpress.com/episodes/the-koinos-whitepaper">Koin Press PodCast on White Paper</a>
โถ๏ธ <a href="https://www.youtube.com/watch?v=v-qFFbDvV2c">Community Member Video</a>
""")
#Get KOIN Virtual Supply
def get_virtual_supply():
url = 'https://checker.koiner.app/koin/virtual-supply'
response = requests.get(url)
data = response.json()
return data
@bot.message_handler(commands=['supply'])
async def handle_supply(message):
data = get_virtual_supply()
await send_message(f"""The Virtual Supply ($KOIN+$VHP) is: {data}.
For more information, read about Koinos' <a href="https://docs.koinos.io/overview/tokenomics/">tokenomics</a>!""")
#Get VHP Total Supply
def get_vhp_supply():
url = 'https://checker.koiner.app/vhp/total-supply'
response = requests.get(url)
data = response.json()
return data
@bot.message_handler(commands=['vhpsupply'])
async def handle_vhp_supply(message):
data = get_vhp_supply()
await send_message(f"""The Total Supply of $VHP is: {data}.
For more information, read about Koinos' <a href="https://docs.koinos.io/overview/tokenomics/">tokenomics</a>!""")
#link to Koinos Forum Guides#
@bot.message_handler(commands=['guides', 'docs'])
async def handle_guides(message):
await send_message("""
๐ <a href="https://docs.koinos.io">Official Koinos documentation</a>
๐ <a href="https://www.youtube.com/watch?v=UFniurcWDcM">How to bridge with Chainge Finance</a>
๐ฎ <a href="https://docs.koinos.io/overview/mana/">Everything you need to know about Mana</a>
""")
#Link to Various social groups
@bot.message_handler(commands=['international'])
async def handle_international(message):
await send_message("""๐ Unofficial International Groups ๐
๐ฉ๐ช <a href="https://t.me/koinosgermany">Deutsch</a>
๐ช๐ธ <a href="https://t.me/koinoshispano">Espaรฑol</a>
๐จ๐ณ <a href="https://t.me/koinos_cn">ไธญๆ</a>
๐ฎ๐น <a href="https://t.me/+8KIVdg8vhIQ5ZGY0">Italiano</a>
๐ฎ๐ท <a href="https://t.me/PersianKoinos">Persian</a>
๐น๐ท <a href="https://t.me/+ND37ePjNlvc4NGE0">Turkish</a>
๐ท๐บ <a href="https://t.me/koinosnetwork_rus">Russian</a>
๐ณ๐ฑ <a href="https://t.me/KoinosNederland">Dutch</a>
""")
@bot.message_handler(commands=['exchange','exchanges','cex','buy'])
async def handle_exchanges(message):
await send_message("""๐ฎ $KOIN is supported on the following exchanges
๐ <b>Bridges</b>:
<a href="https://dapp.chainge.finance/?fromChain=ETH&toChain=ETH&fromToken=USDT&toToken=KOIN">Chainge</a>
๐ <b>DEXs</b>:
<a href="https://app.uniswap.org/explore/tokens/ethereum/0xed11c9bcf69fdd2eefd9fe751bfca32f171d53ae">Uniswap</a>
<a href="https://app.koindx.com/swap">KoinDX</a>
๐ <b>CEXs</b>:
<a href="https://www.mexc.com/exchange/KOIN_USDT">MEXC</a>
<a href="https://bingx.com/en/spot/KOINUSDT/">BingX</a>
<a href="https://www.biconomy.com/exchange/KOIN_USDT">Biconomy</a>
<a href="https://www.coinstore.com/#/spot/KOINUSDT">Coinstore</a>
<a href="https://exchange.lcx.com/trade/KOIN-EUR">LCX</a>
๐จ Exchange Listings are always being pursued! We cannot discuss potential or in progress listings. \
You are free to request specific exchanges but do not be disappointed when you do not receive a response.
""")
#Mana Descriptor
@bot.message_handler(commands=['mana'])
async def hanlde_mana(message):
await send_message("""
๐ฎ Mana is behind the magic of Koinos. Every KOIN inherently contains Mana, \
which is used when using the Koinos blockchain. And just like in video games, \
your Mana recharges over time letting you continue to use Koinos forever!
<a href="https://docs.koinos.io/overview/mana/">Learn more about Mana!</a>
""")
#Media Links
@bot.message_handler(commands=['media','social'])
async def handle_media(message):
await send_message("""
๐ฎ <b>Official Koinos Media</b>
<a href="https://twitter.com/koinosnetwork">Koinos Network X</a>
<a href="https://twitter.com/TheKoinosGroup">Koinos Group X</a>
<a href="https://discord.koinos.io">Discord</a>
<a href="https://medium.com/koinosnetwork">Medium</a>
<a href="https://www.youtube.com/@KoinosNetwork">YouTube</a>
โก <b>Unofficial Koinos Media</b>
<a href="https://koinosnews.com/">Koinos News</a>
<a href="https://www.youtube.com/@motoengineer.koinos">motoengineer YouTube</a>
<a href="https://t.me/KoinosNews">Koinos News Telegram</a>
<a href="https://t.me/thekoinosarmy">Koinos Army Telegram</a>
Also check out /international for international communities!
""")
#Listing of Koinos Projects
@bot.message_handler(commands=['projects'])
async def handle_projects(message):
await send_message("""
๐ฎ Existing Koinos Projects ๐ฎ
๐ <b>dApps:</b>
<a href="https://koindx.com">KoinDX</a>
<a href="https://kollection.app">Kollection</a>
<a href="https://koincity.com">Koincity</a>
<a href="https://koinosbox.com/nicknames">Nicknames</a>
<a href="https://kanvas-app.com">Kanvas</a>
<a href="https://koinosgarden.com">Koinos Garden</a>
๐ฎ <b>Games:</b>
<a href="https://www.lordsforsaken.com/">Lord's Forsaken</a>
<a href="https://planetkoinos.com/space_striker.html">Space Striker</a>
โ๏ธ <b>Mining Pools:</b>
<a href="https://fogata.io">Fogata</a>
<a href="https://burnkoin.com">Burn Koin</a>
๐ <b>Block Explorers:</b>
<a href="https://koiner.app">Koiner</a>
<a href="https://koinosblocks.com">KoinosBlocks</a>
๐ณ <b>Wallets:</b>
<a href="https://chrome.google.com/webstore/detail/kondor/ghipkefkpgkladckmlmdnadmcchefhjl">Kondor</a>
<a href="https://konio.io">Konio</a>
<a href="https://portal.armana.io">Portal</a>
๐ป <b>Misc:</b>
<a href="https://planetkoinos.com/koinos_ai.html">Koinos AI</a>
""")
#Link to Koinos Roadmap
@bot.message_handler(commands=['roadmap'])
async def handle_roadmap(message):
await send_message("""
๐ <a href="https://koinos.io/#roadmap">The official Koinos Network roadmap</a>
""")
#Link to price chat and MEXC
@bot.message_handler(commands=['price'])
async def handle_price(message):
await send_message("""๐จ Please keep price chats out of this group. \
To talk about price, please visit the <a href="https://t.me/thekoinosarmy">Koinos Army Telegram</a>!
๐ต Find the price of $KOIN on <a href="https://www.coingecko.com/en/coins/koinos">CoinGecko</a>.""")
#Provides information about Koinos Wallets
@bot.message_handler(commands=['wallets'])
async def handle_wallets(message):
await send_message("""๐ณ These are the recommended wallets to use with Koinos! \
Choose one or use a combination for security and accessibility!
โก๏ธ <a href="https://chrome.google.com/webstore/detail/kondor/ghipkefkpgkladckmlmdnadmcchefhjl"><b>Kondor Wallet</b></a>
๐ป Browser extension wallet for Chrome and Brave
Created by Julian Gonzalez
<a href="https://github.com/joticajulian/kondor">Kondor Github</a>
<a href="https://github.com/sponsors/joticajulian">Sponsor Julian</a>
โก๏ธ <a href="https://konio.io"><b>Konio Wallet</b></a>
๐ฑ Mobile Wallet for iOS & Android
Created by Adriano Foschi
<a href="https://github.com/konio-io/konio-mobile">Koinio Github</a>
โก๏ธ <a href="https://tangem.com"><b>Tangem Wallet</b></a>
๐ฑ Hardware Wallet for iOS & Android
More secure but less dApp support
""")
#Give Claim Information
@bot.message_handler(commands=['claim'])
async def handle_claim(message):
await send_message("""
โ ๏ธ Claim information โ ๏ธ
โก๏ธ You are only eligible if you held your ERC-20 KOIN token during the snapshot. \
To verify, find your wallet address in this <a href="https://t.me/koinos_community/109226">snapshot record</a>.
โก๏ธ You will need a Koinos Wallet to hold your main net $KOIN tokens! Use \
<a href="https://chrome.google.com/webstore/detail/kondor/ghipkefkpgkladckmlmdnadmcchefhjl">Kondor</a> to manage your $KOIN.
๐จ SAVE YOUR PRIVATE KEYS OR SEED PHRASES!!! ๐จ
๐จ Seriously, did you back up your private key or seed phrase? We cannot recover them if you lose them.
โถ๏ธ <a href="https://youtu.be/l-5dHGqUSj4">Video Tutorial on how to claim.</a>
๐ <a href="https://medium.com/@kuixihe/a-complete-guide-to-claiming-koin-tokens-edd20e7d9c40">Document tutorial on how to claim.</a>
โก๏ธ There is no time limit to claiming. You may claim at any time!
""")
@bot.message_handler(commands=['programs'])
async def handle_programs(message):
programs = get_programs()
if len(programs) == 0:
await send_message("๐จ There are no active programs at this time.")
return
message = "๐ฎ Koinos active programs!\n"
image = None
for program in programs:
message += f"""
{make_program_blurb(program)}"""
if image == None and program['images'] != None and program['images']['banner'] != None:
image = program['images']['banner']
if image != None:
message = f"""<a href="{image}">‍</a>""" + message
await send_message(message, True)
@bot.message_handler(commands=['rules','guidelines'])
async def handle_rules(message):
await send_message("""Welcome to the Koinos Telegram community!
We kindly ask you follow these guidelines to help create a positive and innovative environment.
โ
Share your projects, discuss features, plans, and seek feedback.
โ
Discuss and build dApps, features, and developments.
โ
Share constructive feedback that leads to improvement.
โ
Maintain a professional, respectful, and valuable conversations.
โ
Grow the ecosystem with insights, resources, and feedback.
โ
Avoid promoting non-utility tokens, projects, or dApps.
โ
Keep discussions on-topic and avoid unrelated content.
โ
Uphold these guidelines and foster a welcoming community.
๐ View complete guidelines \
<a href="https://docs.google.com/document/d/1-WYFlj7p3U0GG5Q5_OQPR5tzRD4WlG3FKNj4u9Lz3vQ/edit?usp=sharing">here</a>.
""")
# Start polling
async def start_polling():
await bot.polling(non_stop=True)
# Gracefully stop polling
async def stop_polling():
await bot.stop_polling() # This will stop the polling process
await bot.close_session() # Close the bot's aiohttp session
async def main():
try:
await start_polling()
except (KeyboardInterrupt, SystemExit):
print("Gracefully stopping the bot...")
await stop_polling()
if __name__ == '__main__':
asyncio.run(main())