" $result]
45 | set start [string first "title=\"" $result $start]
46 | set end [string first "\"" $result [expr $start+7]]
47 | set game1 [string range $result [expr $start+7] $end-1]
48 |
49 | set start [string first "
" $result $start]
50 | set start [string first "title=\"" $result $start]
51 | set end [string first "\"" $result [expr $start+7]]
52 | set game2 [string range $result [expr $start+7] $end-1]
53 |
54 | set start [string first "
" $result $start]
55 | set start [string first "title=\"" $result $start]
56 | set end [string first "\"" $result [expr $start+7]]
57 | set game3 [string range $result [expr $start+7] $end-1]
58 |
59 | set response [::msgcat::mc MSG_PSN_RESULT "$name" "$level" "$game1" "$game2" "$game3"]
60 | # set response "Player: $name%0ALevel: $level%0ARecently seen playing:%0A1. $game1%0A2. $game2%0A3. $game3"
61 | }
62 | libtelegram::sendPhoto $chat_id "https:$userpic" "$response" "html" false $msgid ""
63 | putchan $channel "Player: $name https:[strip_html $userpic]"
64 | } else {
65 | set response "[::msgcat::mc MSG_PSN_NOTFOUND]"
66 | libtelegram::sendMessage $chat_id "$response" "html" false $msgid ""
67 | putchan $channel "[strip_html $response]"
68 | }
69 | return 0
70 | } else {
71 | return -1
72 | }
73 | }
74 |
75 | ::telegram::addPublicTgCommand psn psn_getPSNInfo "[::msgcat::mc MSG_PSN_HELP]"
76 |
--------------------------------------------------------------------------------
/modules/Quotes.conf:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------- #
2 | # Telegram-API Quote module for Eggdrop v20180731 #
3 | # #
4 | # written by Eelco Huininga 2016-2018 #
5 | # ---------------------------------------------------------------------------- #
6 |
7 | # ---------------------------------------------------------------------------- #
8 | # Configuration settings #
9 | # ---------------------------------------------------------------------------- #
10 |
11 | set ::Quotes::quote_database [file join [file dirname [info script]] quote.txt]
12 |
13 | # Messages for the Quote-module
14 | ::msgcat::mcset de MSG_QUOTE_NOTEXIST "Zitat nummer %s nicht gefunden."
15 | ::msgcat::mcset de MSG_QUOTE_NOTFOUND "Kein Zitaten mit %s gefunden."
16 | ::msgcat::mcset de MSG_QUOTE_QUOTEADDED "Zitat ist am der Zitatliste hinzugefügt."
17 | ::msgcat::mcset de MSG_QUOTE_HELP "(Stichwort/id): Sehe sich ein Zitat aus der legendären Zitatdatenbank an."
18 | ::msgcat::mcset de MSG_QUOTE_ADDHELP ": Fügt ein Zitat an der legendären Zitatdatenbank hinzu."
19 |
20 | ::msgcat::mcset en MSG_QUOTE_NOTEXIST "Quote number %s does not exist."
21 | ::msgcat::mcset en MSG_QUOTE_NOTFOUND "No quotes with %s found."
22 | ::msgcat::mcset en MSG_QUOTE_QUOTEADDED "Quote has been added to the quote-list."
23 | ::msgcat::mcset en MSG_QUOTE_HELP "(keyword/id): View a quote from the legendary quote database."
24 | ::msgcat::mcset en MSG_QUOTE_ADDHELP ": Adds a quote to the legendary quote database."
25 |
26 | ::msgcat::mcset nl MSG_QUOTE_NOTEXIST "Quote nummer %s bestaat niet."
27 | ::msgcat::mcset nl MSG_QUOTE_NOTFOUND "Geen quotes met %s gevonden."
28 | ::msgcat::mcset nl MSG_QUOTE_QUOTEADDED "Quote is toegevoegd aan de quote-lijst."
29 | ::msgcat::mcset nl MSG_QUOTE_HELP "(zoekterm/id): Laat een quote uit de legendarische quote database te zien."
30 | ::msgcat::mcset nl MSG_QUOTE_ADDHELP ": Voeg een quote toe aan de legendatische quote database."
31 |
32 |
--------------------------------------------------------------------------------
/modules/Quotes.tcl:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------- #
2 | # Telegram-API Quote module for Eggdrop v20181119 #
3 | # #
4 | # written by Eelco Huininga 2016-2018 #
5 | # ---------------------------------------------------------------------------- #
6 |
7 | namespace eval Quotes {}
8 | source "[file join [file dirname [info script]] Quotes.conf]"
9 |
10 | # ---------------------------------------------------------------------------- #
11 | # Quote procedures #
12 | # ---------------------------------------------------------------------------- #
13 | # Get a quote from the quote-database #
14 | # ---------------------------------------------------------------------------- #
15 |
16 | proc quotes_getQuote {from_id chat_id msgid channel message parameter_start} {
17 | global quote_database
18 |
19 | set quote_id [string trim [string range $message $parameter_start end]]
20 |
21 | set quote_fd [open "$::Quotes::quote_database" r]
22 | for {set quote_count 0} { ![eof $quote_fd] } {incr quote_count} {
23 | gets $quote_fd quote_list($quote_count)
24 | }
25 | close $quote_fd
26 |
27 | set quote_count [expr $quote_count - 1]
28 | if {$quote_id == ""} {
29 | set quote_id [rand $quote_count]
30 | set qot_sel $quote_list($quote_id)
31 | } else {
32 | if {[string is integer $quote_id]} {
33 | unset quote_list($quote_count)
34 | unset quote_list([expr $quote_count - 1])
35 | if {![info exists quote_list([expr {$quote_id} - 1])]} {
36 | set qot_sel [::msgcat::mc MSG_QUOTE_NOTEXIST $quote_id]
37 | } else {
38 | set qot_sel $quote_list([expr {$quote_id} - 1])
39 | }
40 | } else {
41 | set quote_id [string tolower $quote_id]
42 |
43 | set quote_sel_num 0
44 | for {set i 0} {$i < $quote_count} {incr i} {
45 | if {[string first $quote_id [string tolower $quote_list($i)]] != -1} {
46 | set quote_selection($quote_sel_num) $quote_list($i)
47 | incr quote_sel_num
48 | }
49 | }
50 |
51 | if {$quote_sel_num == 0} {
52 | set qot_sel [::msgcat::mc MSG_QUOTE_NOTFOUND $quote_id]
53 | } else {
54 | set qot_sel $quote_selection([set qot_cur [rand $quote_sel_num]])
55 | }
56 | }
57 | }
58 |
59 | ::libtelegram::sendMessage $chat_id "[url_encode $qot_sel]" "html" false $msgid ""
60 | putchan $channel "[::libunicode::utf82ascii $qot_sel]"
61 |
62 | return 0
63 | }
64 |
65 | # ---------------------------------------------------------------------------- #
66 | # Add a quote to the quote-database #
67 | # ---------------------------------------------------------------------------- #
68 |
69 | proc quotes_addQuote {from_id chat_id msgid channel message parameter_start} {
70 | global quote_database
71 |
72 | set quote [string trim [string range $message $parameter_start end]]
73 |
74 | if {$quote ne ""} {
75 | file copy -force "$::Quotes::quote_database" "$::Quotes::quote_database~"
76 | set quote_fd [open "$::Quotes::quote_database" a+]
77 | puts $quote_fd "$quote"
78 | close $quote_fd
79 |
80 | ::libtelegram::sendMessage $chat_id "[::msgcat::mc MSG_QUOTE_QUOTEADDED]" "html" false $msgid ""
81 | putchan $channel "[::msgcat::mc MSG_QUOTE_QUOTEADDED]"
82 |
83 | return 0
84 | } else {
85 | return -1
86 | }
87 | }
88 |
89 | ::telegram::addPublicTgCommand quote quotes_getQuote "[::msgcat::mc MSG_QUOTE_HELP]"
90 | ::telegram::addPublicTgCommand addquote quotes_addQuote "[::msgcat::mc MSG_QUOTE_ADDHELP]"
91 |
--------------------------------------------------------------------------------
/modules/Soundcloud.conf:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------- #
2 | # Telegram-API SoundCloud module for Eggdrop v20180212 #
3 | # #
4 | # written by Eelco Huininga 2016-2018 #
5 | # ---------------------------------------------------------------------------- #
6 |
7 | # ---------------------------------------------------------------------------- #
8 | # Configuration settings #
9 | # ---------------------------------------------------------------------------- #
10 |
11 | # Messages for the Soundcloud-module
12 | ::msgcat::mcset de MSG_SOUNDCLOUD_HELP ": Suche SoundCloud nach Musik, die zu passt."
13 | ::msgcat::mcset de MSG_SOUNDCLOUD_NOTFOUND "Nichts gefunden."
14 | ::msgcat::mcset de MSG_SOUNDCLOUD_NOVALID "Keine gültige Antwort von Soundcloud-Servern erhalten (der Server ist möglicherweise inaktiv)."
15 |
16 | ::msgcat::mcset en MSG_SOUNDCLOUD_HELP ": Search SoundCloud for music matching ."
17 | ::msgcat::mcset en MSG_SOUNDCLOUD_NOTFOUND "Nothing found."
18 | ::msgcat::mcset en MSG_SOUNDCLOUD_NOVALID "Got no valid response from Soundcloud servers (server may be down)."
19 |
20 | ::msgcat::mcset nl MSG_SOUNDCLOUD_HELP ": Zoek muziek op SoundCloud naar ."
21 | ::msgcat::mcset nl MSG_SOUNDCLOUD_NOTFOUND "Niets gevonden."
22 | ::msgcat::mcset nl MSG_SOUNDCLOUD_NOVALID "Geen geldig antwoord gekregen van de Soundcloud servers (server kan onbereikbaar zijn)."
23 |
--------------------------------------------------------------------------------
/modules/Soundcloud.tcl:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------- #
2 | # Soundcloud module for Eggdrop with the Telegram-API module v20181119 #
3 | # #
4 | # written by Eelco Huininga 2016-2018 #
5 | # ---------------------------------------------------------------------------- #
6 |
7 | # ---------------------------------------------------------------------------- #
8 | # Configuration settings #
9 | # ---------------------------------------------------------------------------- #
10 |
11 | source "[file join [file dirname [info script]] Soundcloud.conf]"
12 |
13 | # ---------------------------------------------------------------------------- #
14 | # Soundcloud procedures #
15 | # ---------------------------------------------------------------------------- #
16 | # Search a track on Soundcloud #
17 | # ---------------------------------------------------------------------------- #
18 |
19 | proc soundcloud_getTrack {from_id chat_id msgid channel message parameter_start} {
20 | if {[set query [string map {" " "%20"} [string trim [string range $message $parameter_start end]]]] ne ""} {
21 | if { [ catch {
22 | set result [exec curl --tlsv1.2 -s -X GET https://api.soundcloud.com/tracks.json?client_id=4346c8125f4f5c40ad666bacd8e96498&q=$query&limit=1]
23 | } ] } {
24 | putlog "Soundcloud.tcl: cannot connect to api.soundcloud.com using tracks.json method."
25 | return -1
26 | }
27 |
28 | if {[::libjson::getValue $result "total"] eq "0"} {
29 | set response "[::msgcat::mc MSG_SOUNDCLOUD_NOTFOUND]"
30 | } else {
31 | if {[set response [::libjson::getValue $result "permalink_url"]] eq -1} {
32 | set response "[::msgcat::mc MSG_SOUNDCLOUD_NOVALID]"
33 | }
34 | }
35 |
36 | ::libtelegram::sendMessage $chat_id "$response" "html" false $msgid ""
37 | putchan $channel "[strip_html $response]"
38 |
39 | return 0
40 | } else {
41 | return -1
42 | }
43 | }
44 |
45 | ::telegram::addPublicTgCommand soundcloud soundcloud_getTrack "[::msgcat::mc MSG_SOUNDCLOUD_HELP]"
46 |
--------------------------------------------------------------------------------
/modules/Spotify.conf:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------- #
2 | # Telegram-API Spotify module for Eggdrop v20180212 #
3 | # #
4 | # written by Eelco Huininga 2016-2018 #
5 | # ---------------------------------------------------------------------------- #
6 |
7 | # ---------------------------------------------------------------------------- #
8 | # Configuration settings #
9 | # ---------------------------------------------------------------------------- #
10 |
11 | # Messages for the Spotify-module
12 | ::msgcat::mcset de MSG_SOUNDCLOUD_HELP ": Suche Spotify nach Musik, die zu passt."
13 | ::msgcat::mcset de MSG_SOUNDCLOUD_NOTFOUND "Nichts gefunden."
14 |
15 | ::msgcat::mcset en MSG_SPOTIFY_HELP ": Search Spotify for music matching ."
16 | ::msgcat::mcset en MSG_SPOTIFY_NOTFOUND "Nothing found."
17 |
18 | ::msgcat::mcset nl MSG_SPOTIFY_HELP ": Zoek muziek op Spotify naar ."
19 | ::msgcat::mcset nl MSG_SPOTIFY_NOTFOUND "Niets gevonden."
20 |
--------------------------------------------------------------------------------
/modules/Spotify.tcl:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------- #
2 | # Spotify module for Eggdrop with the Telegram-API module v20181119 #
3 | # #
4 | # written by Eelco Huininga 2016-2018 #
5 | # ---------------------------------------------------------------------------- #
6 |
7 | # ---------------------------------------------------------------------------- #
8 | # Configuration settings #
9 | # ---------------------------------------------------------------------------- #
10 |
11 | source "[file join [file dirname [info script]] Spotify.conf]"
12 |
13 | # ---------------------------------------------------------------------------- #
14 | # Spotify procedures #
15 | # ---------------------------------------------------------------------------- #
16 | # Search a track on Spotify #
17 | # ---------------------------------------------------------------------------- #
18 |
19 | proc spotify_getTrack {from_id chat_id msgid channel message parameter_start} {
20 | if {[set spotifyquery [string map {" " "%20"} [string trim [string range $message $parameter_start end]]]] ne ""} {
21 | if { [ catch {
22 | set result [exec curl --tlsv1.2 -s -X GET https://api.spotify.com/v1/search?q=$spotifyquery&type=track&limit=1]
23 | } ] } {
24 | putlog "Spotify.tcl: cannot connect to api.spotify.com using search method."
25 | return -1
26 | }
27 |
28 | if {[::libjson::hasKey $result ".error"]} {
29 | set response "Error [::libjson::getValue $result ".error.status"] [::libjson::getValue $result ".error.message"]"
30 | } else {
31 | if {[::libjson::getValue $result "total"] eq "0"} {
32 | set response "[::msgcat::mc MSG_SPOTIFY_NOTFOUND]"
33 | } else {
34 | set response [::libjson::getValue $result "spotify"]
35 | }
36 | }
37 |
38 | ::libtelegram::sendMessage $chat_id "$response" "html" false $msgid ""
39 | putchan $channel "[strip_html $response]"
40 |
41 | return 0
42 | } else {
43 | return -1
44 | }
45 | }
46 |
47 | ::telegram::addPublicTgCommand spotify spotify_getTrack "[::msgcat::mc MSG_SPOTIFY_HELP]"
48 |
--------------------------------------------------------------------------------
/web/tg.php:
--------------------------------------------------------------------------------
1 | $file_id_max_length)) {
22 | header ('HTTP/1.0 400 Bad Request');
23 | header ('Content-Type: text/plain');
24 | writeLogfile(" - FAILED file_id length ( bytes)\n");
25 | die ('0x00000001');
26 | }
27 | if (!ctype_print($file_id)) {
28 | header ('HTTP/1.0 400 Bad Request');
29 | header ('Content-Type: text/plain');
30 | writeLogfile(' - FAILED file_id ctype_print\n');
31 | die ('0x00000002');
32 | }
33 | if (preg_match("/[^A-Za-z0-9\-_]/", $file_id)) {
34 | header ('HTTP/1.0 400 Bad Request');
35 | header ('Content-Type: text/plain');
36 | writeLogfile(' - FAILED file_id preg_match\n');
37 | die ('0x00000003');
38 | }
39 |
40 | # Get the link to the attachment
41 | try {
42 | $content = file_get_contents('https://api.telegram.org/bot' . $bot_id . ':' . $bot_token . '/getFile?file_id=' . $file_id, false, NULL, 0, $max_file_size);
43 |
44 | if ($content === false) {
45 | header ('HTTP/1.0 504 Gateway Time-out');
46 | header ('Content-Type: text/plain');
47 | writeLogfile(' - FAILED at getLink1\n');
48 | die ('0x0000001A');
49 | }
50 | } catch (Exception $e) {
51 | header ('HTTP/1.0 400 Bad Request');
52 | header ('Content-Type: text/plain');
53 | // var_dump ($e);
54 | writeLogfile(' - FAILED at getLink2 ' . $e->getMessage() . '\n');
55 | die ('0x0000001B');
56 | }
57 |
58 | # Translate the JSON response from the Telegram server
59 | $json = json_decode(utf8_encode($content), true);
60 |
61 | # Do some sanity checking
62 | if ($json['result']['file_size'] > $max_file_size) {
63 | header ('HTTP/1.0 400 Bad Request');
64 | header ('Content-Type: text/plain');
65 | writeLogfile(' - FAILED file too big (' . $json['result']['file_size'] . ' bytes)\n');
66 | die ('0x0000001C');
67 | }
68 |
69 | # Get the attachment itself from the Telegram server
70 | try {
71 | $content = file_get_contents('https://api.telegram.org/file/bot' . $bot_id . ':' . $bot_token . '/' . $json['result']['file_path'], false, NULL, 0, $max_file_size);
72 |
73 | if ($content === false) {
74 | header ('HTTP/1.0 504 Gateway Time-out');
75 | header ('Content-Type: text/plain');
76 | writeLogfile(' - FAILED at getAttachment1\n');
77 | die ('0x0000002A');
78 | }
79 | } catch (Exception $e) {
80 | header ('HTTP/1.0 400 Bad Request');
81 | header ('Content-Type: text/plain');
82 | // var_dump ($e);
83 | writeLogfile(' - FAILED at getAttachment2 ' . $e->getMessage() . '\n');
84 | die ('0x0000002B');
85 | } finally {
86 | # Prep the appropiate headers
87 | header('Cache-Control: no-cache, must-revalidate');
88 | header('Expires: Wed, 21 Oct 2015 07:28:00 GMT');
89 | header('Content-Length: ' . basename($json['result']['file_size']));
90 | header('Content-Type: application/octet-stream');
91 | header('Content-Disposition: attachment; filename="' . basename($json['result']['file_path']) . '"');
92 |
93 | # Make sure the output buffer is empty, and send the attachment
94 | ob_clean();
95 | flush();
96 | print $content;
97 | writeLogfile('\n');
98 | exit;
99 | }
100 |
101 | function writeLogfile($text) {
102 | global $logfile, $logfileEnabled;
103 |
104 | if ($logfileEnabled) {
105 | file_put_contents($logfile, $text, FILE_APPEND | LOCK_EX);
106 | }
107 | }
108 | ?>
109 |
--------------------------------------------------------------------------------