Esempio n. 1
0
    def test_crypto_btc_to_default(self, mock_http_get):
        mock_http_get.return_value = get_fixture_file(self, 'crypto_btc_to_default.json')

        expected = u'USD/\u0243: \x0307$ 6,084.30\x0f - High: ' \
                   u'\x0307$ 6,178.90\x0f - Low: \x0307$ 6,014.26' \
                   u'\x0f - Volume: \u0243 21,428.7 ' \
                   u'($ 131,067,493.3) - Total Supply: ' \
                   u'\u0243 17,202,675.0 - MktCap: $ 104.67 B'

        say_mock = Mock()
        crypto('btc', say=say_mock)

        say_mock.assert_called_once_with(expected)
Esempio n. 2
0
    def test_crypto_eth_to_default(self, mock_http_get):
        mock_http_get.return_value = get_fixture_file(self, 'crypto_eth_to_default.json')

        expected = u'USD/\u039e: \x0307$ 315.91\x0f - High: ' \
                   u'\x0307$ 332.41\x0f - Low: \x0307$ 312.35\x0f ' \
                   u'- Volume: \u039e 163,011.9 ($ 52,513,531.9) - ' \
                   u'Total Supply: \u039e 101,251,550.4 - ' \
                   u'MktCap: $ 31.99 B'

        say_mock = Mock()
        crypto('eth', say_mock)

        say_mock.assert_called_once_with(expected)
Esempio n. 3
0
    def test_crypto_btc_to_default(self, mock_http_get):
        mock_http_get.return_value = get_fixture_file_data(
            self, 'crypto_btc_to_default.json')

        expected = u'USD/\u0243: \x0307$ 6,084.30\x0f - High: ' \
                   u'\x0307$ 6,178.90\x0f - Low: \x0307$ 6,014.26' \
                   u'\x0f - Volume: \u0243 21,428.7 ' \
                   u'($ 131,067,493.3) - Total Supply: ' \
                   u'\u0243 17,202,675.0 - MktCap: $ 104.67 B'

        say_mock = Mock()
        crypto('btc', say=say_mock)

        say_mock.assert_called_once_with(expected)
Esempio n. 4
0
    def test_crypto_eth_to_default(self, mock_http_get):
        mock_http_get.return_value = get_fixture_file_data(
            self, 'crypto_eth_to_default.json')

        expected = u'USD/\u039e: \x0307$ 315.91\x0f - High: ' \
                   u'\x0307$ 332.41\x0f - Low: \x0307$ 312.35\x0f ' \
                   u'- Volume: \u039e 163,011.9 ($ 52,513,531.9) - ' \
                   u'Total Supply: \u039e 101,251,550.4 - ' \
                   u'MktCap: $ 31.99 B'

        say_mock = Mock()
        crypto('eth', say_mock)

        say_mock.assert_called_once_with(expected)
Esempio n. 5
0
    def test_crypto_eth_to_default(self, mock_http_get):
        mock_http_get.return_value = get_fixture_file_data(
            self, "crypto_eth_to_default.json")

        expected = (u"USD/\u039e: \x0307$ 315.91\x0f - High: "
                    u"\x0307$ 332.41\x0f - Low: \x0307$ 312.35\x0f "
                    u"- Volume: \u039e 163,011.9 ($ 52,513,531.9) - "
                    u"Total Supply: \u039e 101,251,550.4 - "
                    u"MktCap: $ 31.99 B")

        say_mock = Mock()
        crypto("eth", say_mock)

        say_mock.assert_called_once_with(expected)
Esempio n. 6
0
 def __init__(self):
     """@todo: to be defined1. """
     self.c = crypto()
Esempio n. 7
0
FEE = 1.02  # fee for every trade (2%)
Diff = 1.02  # 2 % arbitrage to execute
curr = ["xpm", "ltc", "ftc", "ppc",
        "nmc"]  #currencies to trade if arbitrage is found
exc = ["crypto", "vircu", "btc-e",
       "coins-e"]  #exchanges to trade on for the function calls
# ["btc-e", "vircu", "cryptsy", "coins-e"]
amount1 = 1  #the number of altcoins to be traded vs. btc in each trade

# BTC-e login data:
btce = btc_e_api.API(
    'XJP018WC-35J8SO7G-Z7QH8BDU-JEVRV5VA-G23W3ZSN',
    'caf818fa22084b672a0d53e05fc6f0e903e1e242976034f8aa2666f5c502b497')

#Vircurex Login Data:
vircurex = Account('peanutpower', '745p2V8v5c5J21u')

#Crypto-trade Login Data:
cryp = crypto('67FF99C7-69D1-A090-C3C9-12AB9BD94E14',
              'c27b6251614b4baeebc115358f79697636fa27b6')

#Cryptsy Login Data:
cryptsy = PyCryptsy(
    'db34131d6a8f0bbc19028f322cd22a6b986dde69',
    '79d5bf670a684b3bbbc109f6f64d4ed48c84b1b426546c30a5bcac43d7d8687c2c2d6b96f13b2c2f'
)

#coins-e Login Data:
PUBLIC_KEY = '14def7bc47f9858551b34f7cda5a17d64fe76112c21f53838a03f2f3'
PRIVATE_KEY = 'f0896ce593aa2ed4232dff8abc0581f69fd77bd6eaf8360cf682b462b89cbd31'
Esempio n. 8
0
			# archive the folder
			zip_filename = folder + ".zip"
			print("archive the folder " + zip_filename + "...")
			zip = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED)
			for root, dirs, files in os.walk(filepath) :
				for file in files :
					abspath = os.path.join(root, file)
					relpath = os.path.relpath(os.path.join(root, file), os.path.join(filepath, '..'))
					try: 
						zip.write(relpath)
					except:
						zip.write(abspath, arcname = relpath)
			zip.close()

			# Encrypt the archive
			c = crypto.crypto()
			if output:
				if os.path.isdir(output):
					print("encrypting...")
					c.encrypt_file(password, zip_filename, output_path = output)
					os.remove(zip_filename)
				else:
					print("-o --output should be a folder!")
			else:
				print("encrypting...")
				c.encrypt_file(password, zip_filename)
				os.remove(zip_filename)

		else:
			# Get the filename
			slash_position = reverse_find(filepath, '/')
Esempio n. 9
0
 else:
     #
     # Solicitar mensaje a codificar y mostrarlo
     #
     if var_opcion_3 == 1:
         mensaje = str(
             input("Ingrese Mensaje a Codificar: "))
         accion = var_opcion_3
         print()
         print(
             "*** Resultado de la Función Codificar Mensaje ***"
         )
         print()
         print("Mensaje Original..: ", mensaje)
         print("Mensaje Encryptado: ",
               codi.crypto(mensaje, accion))
     else:
         #
         # Solicitar mensaje a descodificar y mostrarlo
         #
         if var_opcion_3 == 2:
             mensaje = str(
                 input(
                     "Ingrese Mensaje a Descodificar: ")
             )
             accion = var_opcion_3
             print()
             print(
                 "*** Resultado de la Función Descodificar Mensaje ***"
             )
             print()
Esempio n. 10
0
def process_chat(*args):
    # uncomment for debug:
    # print(args)
    try:
        # get vars from args
        ident = args[0]["identifier"]
        message = args[0]["body"]
        name = args[0]["name"]
        count = str(args[0]["count"])
        convo = args[0]["convo"]
        country_name = args[0]["country_name"]
        country = args[0]["country"]
        # checks if file exists an gets the extension of it
        if "image" in args[0].keys():
            extension = os.path.splitext(args[0]["image"])[-1].lower()
        else:
            extension = ''

        # scrapes and returns a random cat image/gif from random.cat
        if re.match('^[.]kit$', message):
            msg = '>>' + count
            f = random.choice([rkot, rkit, rkot])()
            post_chat(msg,
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo='General',
                      file=f)

        # returns one of many 8ball messages
        if re.match('^[.]8ball', message):
            random.shuffle(hbot.ball)
            mesg = random.choice(hbot.ball)
            post_chat('>>' + count + '\n' + mesg,
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo='General',
                      file='')

        # matches cryptocurrencies, returns their data
        if re.match('^[#][a-zA-Z]+$', message):
            msg = detailed(message[1:])
            if msg:
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo='General',
                          file='')

        if re.match('^[$][a-zA-Z]+$', message):
            msg = crypto(message[1:])
            if msg:
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo='General',
                          file='')

        # in case it f***s up and sends empty message
        help_msg = 'no help message defined'

        # money getter
        mreq = re.compile('\.(m|money) (.+)').match(message)
        if mreq:
            try:
                m = mreq.group(2).upper().split(' ')
                if not m[0].isnumeric():
                    m = [1] + m
                msg = money(m)
                if msg:
                    post_chat('>>' + count + '\n' + msg,
                              channel,
                              name=config.name,
                              trip=config.Trip,
                              convo='General',
                              file='')
            except Exception as e:
                print(e)

        # gets weather, sometimes off
        # could be cleaned up but i won't bother right now
        wreq = re.compile('\@(weather|w)( (.+))?').match(message)
        if wreq:
            try:
                w = wreq.group(2)
                if not w:
                    w = regioncodes[country]
                if re.match('us', country[:2].lower()):
                    wttr.weather(w, murrica=False)
                else:
                    wttr.weather(w)
                msg = 'Weather in ' + w
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo='General',
                          file='weather.png')
            except Exception as e:
                print(str(e))

        # translates text into english
        treq = re.compile('(\.t )([\s\S]+)').match(message)
        if treq:
            try:
                msg = ht(treq.group(2))
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo='General',
                          file='')
            except Exception as e:
                print(str(e))

        # checks messages for bot commands
        for (k, v) in hbot.answers.iteritems():
            if re.match(k, message):
                help_msg = hbot.answers[k]
                out_msg = '>>' + count + '\n' + help_msg
                post_chat(out_msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo='General',
                          file='')

        # handles text messages only, text + photo will only be handled as photo by next handler
        @tbot.message_handler(func=lambda incM: True)
        def handle_text(incM):
            post_chat(incM.text,
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo="General",
                      file='')

        # only handles photos, doesnt work with text
        @tbot.message_handler(content_types=['photo', 'text'])
        def handle_image(message):
            file_id = message.photo[-1].file_id
            imageIn = tbot.get_file(file_id)
            image_file = requests.get('https://api.telegram.org/file/bot' +
                                      config.token + '/' + imageIn.file_path)
            with open('in.jpg', 'wb') as f:
                f.write(image_file.content)
            post_chat('',
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo='General',
                      file='in.jpg')

        # only sends posts from 'General' conversation
        if convo == "General":
            if "image" in args[0].keys():
                out_image = args[0]["image"]
                if args[0]["image_filename"].startswith('anna'):
                    out_image = ''
            else:
                out_image = ''

            msg = str(count) + '| ' + name + ' | ' + country + " :\n" + message

            # this doesnt work smh
            try:
                if extension != '.webm':
                    tbot.send_message(config.user_id, msg)
                # will only send images if they exist and nsfw is off
                if out_image != '' and not nsfw and extension != '':
                    if extension not in [
                            '.webm', '.gif', '.ogg', '.mp3', '.mp4'
                    ]:
                        send_image(out_image)
                        img = open('out.jpg', 'rb')
                        tbot.send_photo(config.user_id, img)
                        img.close()
                    if extension == '.ogg':
                        send_file(out_image, extension)
                        ogg = open('out.ogg', 'rb')
                        tbot.send_voice(config.user_id, ogg)
                        ogg.close()
                    if extension == '.gif':
                        send_file(out_image, extension)
                        gif = open('out.gif', 'rb')
                        tbot.send_document(config.user_id, gif)
                        gif.close()
                    if extension == '.mp4':
                        send_file(out_image, extension)
                        video = open('out.mp4', 'rb')
                        tbot.send_video(config.user_id, video)
                        video.close()
                    if extension == '.webm':
                        url = args[0]['image'].replace(
                            '/home/ph/livechan-js/public/',
                            'https://kotchan.org/')
                        msg += '\n' + url
                        tbot.send_message(config.user_id, msg)

            except Exception as e:
                ree = '----------\n' + str(e) + '\n-----------'
                tbot.send_message(config.user_id, ree)
    except Exception as e2:
        print('Exception e2: ' + str(e2))
        print(args[0])
Esempio n. 11
0
 def __init__(self):
     """@todo: to be defined1. """
     self.c = crypto()
Esempio n. 12
0
import os
import sys

cwd = os.getcwd()
sys.path.append( cwd + "/lib" )

import dbclient
import crypto
import editor


count = 1
def test( test, result ) :
    global count
    print( "Test %d : \t%s\t\t - %s" %( count, test, "passed" if result else "failed" ) )
    count = count + 1

dbc = dbclient.dbclient( os.getcwd() + "/my_test_database.db" )
cryptographer = crypto.crypto( "baby steps" )
text = "Mary had a little lamb"
cyphertext = cryptographer.encrypt( text )
edit = editor.editor()

test( "database connectivity test", dbc != None )
test( "encryption test", text == cryptographer.decrypt( cyphertext ) )
test( "editor test", "abc\ndef\n" == edit.edit( "abc" ) )
Esempio n. 13
0

import btc_e_api, thread, time
from time import strftime
from vircurex import *
from PyCryptsy import PyCryptsy
from crypto import crypto

FEE = 1.02 # fee for every trade (2%)
Diff = 1.02 # 2 % arbitrage to execute
curr = ["xpm","ltc","ftc","ppc","nmc"] #currencies to trade if arbitrage is found
exc = ["crypto","vircu","btc-e","coins-e"] #exchanges to trade on for the function calls
# ["btc-e", "vircu", "cryptsy", "coins-e"]
amount1 = 1 #the number of altcoins to be traded vs. btc in each trade

# BTC-e login data:
btce = btc_e_api.API('XJP018WC-35J8SO7G-Z7QH8BDU-JEVRV5VA-G23W3ZSN','caf818fa22084b672a0d53e05fc6f0e903e1e242976034f8aa2666f5c502b497')

#Vircurex Login Data:
vircurex = Account('peanutpower', '745p2V8v5c5J21u')

#Crypto-trade Login Data:
cryp = crypto('67FF99C7-69D1-A090-C3C9-12AB9BD94E14','c27b6251614b4baeebc115358f79697636fa27b6')	

#Cryptsy Login Data:
cryptsy = PyCryptsy('db34131d6a8f0bbc19028f322cd22a6b986dde69', '79d5bf670a684b3bbbc109f6f64d4ed48c84b1b426546c30a5bcac43d7d8687c2c2d6b96f13b2c2f')

#coins-e Login Data:
PUBLIC_KEY = '14def7bc47f9858551b34f7cda5a17d64fe76112c21f53838a03f2f3'
PRIVATE_KEY = 'f0896ce593aa2ed4232dff8abc0581f69fd77bd6eaf8360cf682b462b89cbd31'
Esempio n. 14
0
def process_chat(*args):
    # uncomment for debug:
    # print(args)
    try:
        # get vars from args
        ident = args[0]["identifier"]
        message = args[0]["body"]
        name = args[0]["name"]
        count = str(args[0]["count"])
        convo = args[0]["convo"]
        country_name = args[0]["country_name"]
        country = args[0]["country"]
        trip = args[0].get("trip", '')
        # checks if file exists an gets the extension of it
        if "image" in args[0].keys():
            extension = os.path.splitext(args[0]["image"])[-1].lower()
        else:
            extension = ''

        # scrapes and returns a random cat image/gif from random.cat
        if re.match('^[.](kit|whale)$', message):
            msg = '>>' + count
            f = random.choice([rkot, rkit, rkot, rkat])()
            post_chat(msg,
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo=convo,
                      file=f)

        # returns one of many 8ball messages
        if re.match('^[.]8ball', message):
            random.shuffle(hbot.ball)
            mesg = random.choice(hbot.ball)
            post_chat('>>' + count + '\n' + mesg,
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo=convo,
                      file='')

        # matches cryptocurrencies, returns their data
        if re.match('^[#][a-zA-Z]+$', message):
            msg = detailed(message[1:])
            if msg:
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='')

        # matches crypto but just returns price data
        if re.match('^[$][a-zA-Z]+$', message):
            msg = crypto(message[1:])
            if msg:
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='')

        # returns punto switcher-like string if someone f****d up and typed in russian
        sreq = re.compile('\.(sw|switch) ([\s\S]+)').match(message)
        if sreq:
            msg = switch(sreq.group(2))
            if msg:
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='')

        # same but from english
        ssreq = re.compile('\.(bs|bswitch) ([\s\S]+)').match(message)
        if ssreq:
            msg = switchback(ssreq.group(2))
            if msg:
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='')

        # in case it f***s up and sends empty message
        help_msg = 'no help message defined'

        # money getter
        mreq = re.compile('\.(m|money) (.+)').match(message)
        if mreq:
            try:
                m = mreq.group(2).upper().split(' ')
                if not m[0].isnumeric():
                    m = [1] + m
                msg = money(m)
                if msg:
                    post_chat('>>' + count + '\n' + msg,
                              channel,
                              name=config.name,
                              trip=config.Trip,
                              convo=convo,
                              file='')
            except Exception as e:
                print(e)

        meanreq = re.compile('\.(meaning|dict|d) (\D+)').match(message)
        if meanreq:
            msg = meaning(meanreq.group(2))
            post_chat('>>' + count + '\n' + msg,
                      channel,
                      name=config.name,
                      trip=config.Trip,
                      convo=convo,
                      file='')

        # gets weather, sometimes off
        # could be cleaned up but i won't bother right now
        wreq = re.compile('\@(weather|w)( (.+))?').match(message)
        if wreq:
            try:
                w = wreq.group(2)
                if not w:
                    w = regioncodes[country]
                if re.match('us', country[:2].lower()):
                    wttr.weather(w, murrica=False)
                else:
                    wttr.weather(w)
                msg = 'Weather in ' + w
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='weather.png')
            except Exception as e:
                print(str(e))

        # translates text into english
        treq = re.compile('(\.t )([\s\S]+)').match(message)
        if treq:
            try:
                msg = ht(treq.group(2))
                post_chat('>>' + count + '\n' + msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='')
            except Exception as e:
                print(str(e))

        ttsreq = re.compile('([.]tts )([\s\S]+)').match(message)
        if ttsreq:
            try:
                tts(ttsreq.group(2))
                post_chat('>>' + count,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='tts.ogg')
            except Exception as e:
                print(str(e))

        # checks messages for bot commands
        for (k, v) in hbot.answers.iteritems():
            if re.match(k, message):
                help_msg = hbot.answers[k]
                out_msg = '>>' + count + '\n' + help_msg
                post_chat(out_msg,
                          channel,
                          name=config.name,
                          trip=config.Trip,
                          convo=convo,
                          file='')

        @tbot.message_handler(commands=['setname', 'seticon'])
        def handle_set(message):
            cmd, val = message.text.split(None, 1)
            id = message.from_user.id
            oldval = members.get(id, [message.from_user.first_name, 'bug'])
            if cmd == '/setname':
                oldval[0] = val
            elif cmd == '/seticon':
                oldval[1] = val
            members[id] = oldval
            pickle.dump(members, open('members', 'w'))

        # handles text messages only, text + photo will only be handled as photo by next handler
#telegram area, comment out

        @tbot.message_handler(func=lambda incM: True)
        def handle_text(incM):
            id = incM.from_user.id
            text = incM.text
            if incM.reply_to_message:
                origid = (incM.reply_to_message.caption
                          or incM.reply_to_message.text).split()[0]
                text = '>>%s\n%s' % (origid, text)
            name, trip = members.get(id, [incM.from_user.first_name, 'bug'])
            post_chat(text,
                      channel,
                      name=name,
                      trip=trip,
                      convo="General",
                      file='')
            requests.get(
                'https://api.telegram.org/bot{0}/deletemessage?message_id={1}&chat_id={2}'
                .format(config.token, incM.message_id, config.user_id))

        @tbot.message_handler(content_types=['sticker'])
        def handle_sticker(message):
            f = tbot.download_file(
                tbot.get_file(message.sticker.file_id).file_path)
            open('sticker.webp', 'w').write(f)
            f = Image.open('sticker.webp')
            f.save('sticker.jpg', 'JPEG')

            id = message.from_user.id
            name, trip = members.get(id, [message.from_user.first_name, 'bug'])

            post_chat('',
                      channel,
                      name=name,
                      trip=trip,
                      convo='General',
                      file='sticker.jpg')
            requests.get(
                'https://api.telegram.org/bot{0}/deletemessage?message_id={1}&chat_id={2}'
                .format(config.token, message.message_id, config.user_id))

        # only handles photos, doesnt work with text
        @tbot.message_handler(content_types=['photo', 'text'])
        def handle_image(message):
            message_id = message.message_id
            id = message.from_user.id
            name, trip = members.get(id, [message.from_user.first_name, 'bug'])
            file_id = message.photo[-1].file_id
            imageIn = tbot.get_file(file_id)
            image_file = requests.get('https://api.telegram.org/file/bot' +
                                      config.token + '/' + imageIn.file_path)
            with open('in.jpg', 'wb') as f:
                f.write(image_file.content)
            post_chat(message.caption or '',
                      channel,
                      name=name,
                      trip=trip,
                      convo='General',
                      file='in.jpg')
            requests.get(
                'https://api.telegram.org/bot{0}/deletemessage?message_id={1}&chat_id={2}'
                .format(config.token, message.message_id, config.user_id))

        @tbot.message_handler(content_types=['video', 'video_note'])
        def handle_image(message):
            message_id = message.message_id
            id = message.from_user.id
            name, trip = members.get(id, [message.from_user.first_name, 'bug'])
            if message.video_note:
                file_id = message.video_note.file_id
            else:
                file_id = message.video.file_id
            imageIn = tbot.get_file(file_id)
            image_file = requests.get('https://api.telegram.org/file/bot' +
                                      config.token + '/' + imageIn.file_path)
            with open('in.mp4', 'wb') as f:
                f.write(image_file.content)
            post_chat(message.caption or '',
                      channel,
                      name=name,
                      trip=trip,
                      convo='General',
                      file='in.mp4')
            requests.get(
                'https://api.telegram.org/bot{0}/deletemessage?message_id={1}&chat_id={2}'
                .format(config.token, message.message_id, config.user_id))

        # only sends posts from 'General' conversation
        if convo == "General" and not name.endswith('_'):
            if "image" in args[0].keys():
                out_image = args[0]["image"]
                if args[0]["image_filename"].startswith('anna'):
                    out_image = ''
            else:
                out_image = ''

            # msg = str(count) + '| ' + name + ' | ' + tripmap.get(trip, '') + ' | '  + country + " " + regioncodes.get(country, '') + ":\n" + message
            country2 = emoji_flags.get_flag(country.split('-')[0])
            if '-' in country:
                country2 = '%s-%s' % (country2, country.split('-')[1])
            msg = '%s %s %s %s:\n%s' % (count, name, tripmap.get(
                trip, ''), country2, message)

            # this doesnt work smh
            try:
                if extension != '.webm':
                    reply_to_message_id = ids.get(
                        message.startswith('>>')
                        and message.lstrip('>').split()[0])
                    if out_image and extension and extension not in [
                            '.webm', '.gif', '.ogg', '.mp3', '.mp4'
                    ]:
                        send_image(out_image)
                        newmsg = tbot.send_photo(
                            config.user_id,
                            open('out.jpg', 'rb'),
                            caption=msg,
                            reply_to_message_id=reply_to_message_id)
                    else:
                        newmsg = tbot.send_message(
                            config.user_id,
                            msg,
                            reply_to_message_id=reply_to_message_id
                        )  #, parse_mode="Markdown")
                    ids[count] = newmsg.message_id
                    pickle.dump(ids, open('ids', 'w'))
                for st in re.findall(r'\[st\]([\w\d\-\.]+)\[\/st\]', msg):
                    tbot.send_photo(
                        config.user_id,
                        open(
                            '/home/ph/livechan-js/public/images/stickers/%s.png'
                            % st))

                # will only send images if they exist and nsfw is off
                if out_image != '' and not nsfw and extension != '':
                    #if extension not in ['.webm', '.gif', '.ogg', '.mp3', '.mp4']:
                    #    send_image(out_image)
                    #    img = open('out.jpg', 'rb')
                    #    tbot.send_photo(config.user_id, img, caption=msg)
                    #    img.close()
                    if extension == '.ogg':
                        send_file(out_image, extension)
                        ogg = open('out.ogg', 'rb')
                        tbot.send_voice(config.user_id, ogg)
                        ogg.close()
                    if extension == '.gif':
                        send_file(out_image, extension)
                        gif = open('out.gif', 'rb')
                        tbot.send_document(config.user_id, gif)
                        gif.close()
                    if extension == '.mp4':
                        send_file(out_image, extension)
                        video = open('out.mp4', 'rb')
                        tbot.send_video(config.user_id, video)
                        video.close()
                    if extension == '.webm':
                        url = args[0]['image'].replace(
                            '/home/ph/livechan-js/public/',
                            'https://kotchan.org/')
                        msg += '\n' + url
                        tbot.send_message(config.user_id, msg)

            except Exception as e:
                ree = '----------\n' + str(e) + '\n-----------'
                tbot.send_message(config.user_id, ree)
    except Exception as e2:
        print('Exception e2: ' + str(e2))
        print(args[0])
Esempio n. 15
0
def cryptoClass():
    return crypto()