-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods_bool.py
executable file
·54 lines (41 loc) · 1.17 KB
/
methods_bool.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
#!/usr/bin/env python
header = '''package telegram
// THIS FILE IS GENERATED AUTOMATICALLY. DO NOT CHANGE IT
import "context"
'''
methods = '''
AnswerCallbackQuery CallbackQueryAnswer
DeleteMessage DeletedMessage
'''.split()
method_template = '''
// https://core.telegram.org/bots/api#{api_method_lower}
func (b *bot) {method}(ctx context.Context, v *{value}) error {
var ok bool
if err := b.do(ctx, "{api_method}", v, &ok); err != nil {
return err
}
if !ok {
return ErrNotAnswered
}
return nil
}
'''
def replace(template, replacements):
s = template
for key, value in replacements.items():
s = s.replace(key, value)
return s
def main():
pairs = zip(methods[::2], methods[1::2])
with open('methods_bool.go', 'w') as f:
f.write(header)
for method, value in pairs:
api_method = method[0].lower() + method[1:]
f.write(replace(method_template, {
'{method}': method,
'{value}': value,
'{api_method}': api_method,
'{api_method_lower}': api_method.lower(),
}))
if __name__ == '__main__':
main()