|
1 | | -from talkops import Extension, Image, Video |
| 1 | +from talkops import Extension, Image, Parameter, Video |
2 | 2 | import asyncio |
3 | 3 | import random |
4 | 4 |
|
| 5 | +extension = ( |
| 6 | + Extension() |
| 7 | + .set_name('Playground Python') |
| 8 | + .set_icon('https://talkops.app/images/extensions/playground-python.png') |
| 9 | + .set_category('utility') |
| 10 | + .set_demo(True) |
| 11 | + .set_features([ |
| 12 | + 'Enable the alarm', |
| 13 | + 'Receive a random dice', |
| 14 | + 'Receive a random dice asynchronously', |
| 15 | + 'Receive a random dice as message', |
| 16 | + 'Receive a random dice as notification', |
| 17 | + 'Receive a random image', |
| 18 | + 'Receive a random video' |
| 19 | + ]) |
| 20 | +) |
| 21 | + |
| 22 | +color = ( |
| 23 | + Parameter('COLOR') |
| 24 | + .set_description('The color used for test.') |
| 25 | + .set_type('select') |
| 26 | + .set_default_value('blue') |
| 27 | + .set_available_values(['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']) |
| 28 | +) |
| 29 | + |
| 30 | +email = ( |
| 31 | + Parameter('EMAIL') |
| 32 | + .set_description('The email used for test.') |
| 33 | + .set_type('email') |
| 34 | + .set_default_value('john.doe@example.com') |
| 35 | +) |
| 36 | + |
5 | 37 | def enable_alarm(): |
6 | 38 | extension.enable_alarm() |
7 | 39 | return 'Done.' |
@@ -30,67 +62,90 @@ def receive_random_image(): |
30 | 62 | def receive_random_video(): |
31 | 63 | extension.send_medias([ |
32 | 64 | Video(random.choice([ |
33 | | - 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', |
34 | | - 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4', |
35 | | - 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4', |
36 | | - 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4' |
| 65 | + 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', |
| 66 | + 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4', |
| 67 | + 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4', |
| 68 | + 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4' |
37 | 69 | ])) |
38 | 70 | ]) |
39 | 71 | return 'Done.' |
40 | 72 |
|
41 | | -extension = ( |
42 | | - Extension() |
43 | | - .set_name('Playground Python') |
44 | | - .set_icon('https://talkops.app/images/extensions/playground-python.png') |
45 | | - .set_category('utility') |
46 | | - .set_demo(True) |
47 | | - .set_features([ |
48 | | - 'Enable the alarm', |
49 | | - 'Receive a random dice', |
50 | | - 'Receive a random dice asynchronously', |
51 | | - 'Receive a random dice as message', |
52 | | - 'Receive a random dice as notification', |
53 | | - 'Receive a random image', |
54 | | - 'Receive a random video' |
55 | | - ]) |
56 | | - .set_function_schemas([ |
57 | | - { |
58 | | - "name": "enable_alarm", |
59 | | - "description": "Enable the alarm." |
60 | | - }, |
61 | | - { |
62 | | - "name": "receive_random_dice", |
63 | | - "description": "Receive a random dice.", |
64 | | - }, |
65 | | - { |
66 | | - "name": "receive_random_dice_asynchronously", |
67 | | - "description": "Receive a random dice asynchronously.", |
68 | | - }, |
69 | | - { |
70 | | - "name": "receive_random_dice_message", |
71 | | - "description": "Receive a random dice as message.", |
72 | | - }, |
73 | | - { |
74 | | - "name": "receive_random_dice_notification", |
75 | | - "description": "Receive a random dice as notification.", |
76 | | - }, |
77 | | - { |
78 | | - "name": "receive_random_image", |
79 | | - "description": "Receive a random image." |
80 | | - }, |
81 | | - { |
82 | | - "name": "receive_random_video", |
83 | | - "description": "Receive a random video." |
84 | | - } |
85 | | - ]) |
86 | | - .set_functions([ |
87 | | - enable_alarm, |
88 | | - receive_random_dice, |
89 | | - receive_random_dice_asynchronously, |
90 | | - receive_random_dice_message, |
91 | | - receive_random_dice_notification, |
92 | | - receive_random_image, |
93 | | - receive_random_video, |
94 | | - ]) |
95 | | - .start() |
| 73 | +def on_boot(language): |
| 74 | + print("on_boot") |
| 75 | + print(language) |
| 76 | + print(color.value) |
| 77 | + print(email.value) |
| 78 | + |
| 79 | +def on_session(language): |
| 80 | + print("on_session") |
| 81 | + print(language) |
| 82 | + print(color.value) |
| 83 | + print(email.value) |
| 84 | + |
| 85 | +def on_enable(language): |
| 86 | + print("on_enable") |
| 87 | + print(language) |
| 88 | + print(color.value) |
| 89 | + print(email.value) |
| 90 | + |
| 91 | +def on_disable(language): |
| 92 | + print("on_disable") |
| 93 | + print(language) |
| 94 | + print(color.value) |
| 95 | + print(email.value) |
| 96 | + |
| 97 | +def on_language(language): |
| 98 | + print("on_language") |
| 99 | + print(language) |
| 100 | + print(color.value) |
| 101 | + print(email.value) |
| 102 | + |
| 103 | +( |
| 104 | + extension |
| 105 | + .set_parameters([color, email]) |
| 106 | + .set_function_schemas([ |
| 107 | + { |
| 108 | + "name": "enable_alarm", |
| 109 | + "description": "Enable the alarm." |
| 110 | + }, |
| 111 | + { |
| 112 | + "name": "receive_random_dice", |
| 113 | + "description": "Receive a random dice.", |
| 114 | + }, |
| 115 | + { |
| 116 | + "name": "receive_random_dice_asynchronously", |
| 117 | + "description": "Receive a random dice asynchronously.", |
| 118 | + }, |
| 119 | + { |
| 120 | + "name": "receive_random_dice_message", |
| 121 | + "description": "Receive a random dice as message.", |
| 122 | + }, |
| 123 | + { |
| 124 | + "name": "receive_random_dice_notification", |
| 125 | + "description": "Receive a random dice as notification.", |
| 126 | + }, |
| 127 | + { |
| 128 | + "name": "receive_random_image", |
| 129 | + "description": "Receive a random image." |
| 130 | + }, |
| 131 | + { |
| 132 | + "name": "receive_random_video", |
| 133 | + "description": "Receive a random video." |
| 134 | + } |
| 135 | + ]) |
| 136 | + .set_functions([ |
| 137 | + enable_alarm, |
| 138 | + receive_random_dice, |
| 139 | + receive_random_dice_asynchronously, |
| 140 | + receive_random_dice_message, |
| 141 | + receive_random_dice_notification, |
| 142 | + receive_random_image, |
| 143 | + receive_random_video, |
| 144 | + ]) |
| 145 | + .on('enable', on_enable) |
| 146 | + .on('boot', on_boot) |
| 147 | + .on('disable', on_disable) |
| 148 | + .on('language', on_language) |
| 149 | + .on('session', on_session) |
| 150 | + .start() |
96 | 151 | ) |
0 commit comments