5
5
cli = BotCli ("echobot" )
6
6
7
7
8
+ @cli .on_init
9
+ def on_init (bot , args ):
10
+ bot .logger .info ("Initializing CLI with args: %s" , args )
11
+ for accid in bot .rpc .get_all_account_ids ():
12
+ if not bot .rpc .get_config (accid , "displayname" ):
13
+ bot .rpc .set_config (accid , "displayname" , "EchoBot" )
14
+ status = "I am a Delta Chat bot, I will repeat anything you say to me"
15
+ bot .rpc .set_config (accid , "selfstatus" , status )
16
+ bot .rpc .set_config (accid , "delete_server_after" , "1" ) # delete immediately from server
17
+ # bot.rpc.set_config(accid, "delete_device_after", "3600")
18
+
19
+
20
+ @cli .on_start
21
+ def on_start (bot , _args ):
22
+ bot .logger .info (
23
+ "Bot is listening to requests... here connect to databases, start worker threads, etc"
24
+ )
25
+
26
+
8
27
@cli .on (events .RawEvent )
9
- def log_event (bot , _accid , event ):
28
+ def log_event (bot , accid , event ):
10
29
if event .kind == EventType .INFO :
11
- bot .logger .info (event .msg )
30
+ bot .logger .debug (event .msg )
12
31
elif event .kind == EventType .WARNING :
13
32
bot .logger .warning (event .msg )
14
33
elif event .kind == EventType .ERROR :
15
34
bot .logger .error (event .msg )
35
+ elif event .kind == EventType .SECUREJOIN_INVITER_PROGRESS :
36
+ if event .progress == 1000 :
37
+ # bot's QR scanned by an user, send introduction message
38
+ chatid = bot .rpc .create_chat_by_contact_id (accid , event .contact_id )
39
+ reply = {"text" : "Hi, I will repeat anything you say to me" }
40
+ bot .rpc .send_msg (accid , chatid , reply )
16
41
17
42
18
43
@cli .on (events .NewMessage (is_info = False , func = is_not_known_command ))
@@ -27,22 +52,6 @@ def _help(bot, accid, event):
27
52
bot .rpc .send_msg (accid , msg .chat_id , {"text" : "I will repeat anything you say to me" })
28
53
29
54
30
- @cli .on_init
31
- def on_init (bot , args ):
32
- bot .logger .info ("Initializing CLI with args: %s" , args )
33
- for accid in bot .rpc .get_all_account_ids ():
34
- if not bot .rpc .get_config (accid , "displayname" ):
35
- bot .rpc .set_config (accid , "displayname" , "EchoBot" )
36
- status = "I am a Delta Chat bot, I will repeat anything you say to me"
37
- bot .rpc .set_config (accid , "selfstatus" , status )
38
- bot .rpc .set_config (accid , "delete_server_after" , "1" ) # delete immediately from server
39
-
40
-
41
- @cli .on_start
42
- def on_start (bot , _args ):
43
- bot .logger .info ("Running bot..." )
44
-
45
-
46
55
def test (_cli , bot , args ):
47
56
"""just some example subcommand"""
48
57
bot .logger .info ("Hello %s, this is an example subcommand!" , args .name )
0 commit comments