Beispiel #1
0
 def __init__(self):
     self.relative_path = os.path.dirname(os.path.abspath(__file__))
     self.config = utility_func.load_json(
         f'{self.relative_path}/config/setup.json')
     self.sent = utility_func.load_json(
         f'{self.relative_path}/data/persistent-sent.json')
     self.airdropConf = utility_func.load_json(
         f'{self.relative_path}/data/current-airdrop.json')
     self.wallet = utility_func.load_json(
         f'{self.relative_path}/config/wallet-config.json')
     self.batch_log = f'{self.relative_path}/batch-log.txt'
    def __init__(self, bot):
        self.bot = bot

        # config(s)
        self.config = utility.load_json('./config/setup.json')
        self.twitter = utility.load_json('./config/twitter-config.json')

        # interface
        self.color = 0x1e7180
        self.error = 0xcc0000

        self.twitter_auth = twitter.TwitterAuth()
    async def dfa_stats(self, ctx):
        twitter_data = utility.load_json(self.config['twitter'])
        verified = 0
        n_verified = 0

        for v in twitter_data['airdrop-users']:
            id = list(v.keys())[0]

            if v[id][0]['verified'] == True:
                verified += 1
            if v[id][0]['verified'] == False:
                n_verified += 1

        embed = discord.Embed(color=self.color,
                              title=self.config['title'],
                              url=self.config['url'])
        embed.set_thumbnail(url=self.config['thumbnail'])
        embed.add_field(name="Total users registered",
                        value=f"{len(twitter_data['airdrop-users'])}",
                        inline=False)
        embed.add_field(name="Verified", value=f"{verified}", inline=True)
        embed.add_field(name="Non-verified",
                        value=f"{n_verified}",
                        inline=True)
        await ctx.send(embed=embed)
Beispiel #4
0
    def timeline_retweets(self, id):
        retweets = []
        user = self.getUserById(id)
        timeline = self.getTimelineById(id)

        try:
            if int(user['statuses_count']) > 10:
                for i in range(0, 10):
                    if 'retweeted_status' in utility_func.parse2json(
                            timeline[i]):
                        retweets.append(timeline[i]['retweeted_status']['id'])
                    else:
                        continue
            else:
                for i in range(0, int(user['statuses_count'])):
                    if 'retweeted_status' in utility_func.parse2json(
                            timeline[i]):
                        retweets.append(timeline[i]['retweeted_status']['id'])
                    else:
                        continue

            if int(
                    utility_func.load_json('./config/twitter-config.json')
                ['retweet-id']) in retweets:
                return True
            else:
                return False
        except tweepy.TweepError as error:
            print(f"[!] error captured: {error.api_code}")
            pass
class Dyluminati_commands(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
        self.config = utility_func.load_json('./config/setup.json')
        self.color = 0x1e7180
        self.error = 0xcc0000

    roles = utility_func.load_json('./config/setup.json')['discord-roles']

    @commands.command()
    @commands.has_any_role(*roles)
    async def test(self, ctx):
        embed = discord.Embed(color=self.color, timestamp=datetime.utcnow())
        embed.set_thumbnail(url=self.config['thumbnail'])
        embed.set_author(name="Example author", icon_url=self.config['thumbnail'])
        embed.add_field(name='Field2', value='Text2', inline=True)
        embed.add_field(name='Field3', value='Text3', inline=False)
        await ctx.send(embed=embed)
Beispiel #6
0
async def currentBlockHeight():
    while not client.is_closed():
        try:
            await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"block height {rpc_json.getTotalBlocks()}"))
            await asyncio.sleep(30)
        except Exception as currBlockHeight_err:
            print (f"Exception raised: unable to get block height\n{currBlockHeight_err}")
            await asyncio.sleep(120)

@client.event
async def on_ready():
    print('Starting bot...')
    print(f'[USERNAME] :: {client.user.name}')
    print(f'[ID] :: {client.user.id}')
    await client_extensions()
    client.loop.create_task(currentBlockHeight())

async def client_extensions():
    for extension in [f.replace(".py", "") for f in listdir("cogs") if isfile(join("cogs", f))]:
        try:
            if not "__init__" in extension:
                print(f"loading extension: {extension}")
                client.load_extension("cogs.%s" % (extension))
        except:
            print ("failed to load extension {}".format(extension))
            traceback.print_exc()

if __name__ == '__main__':
    client.run(utility_func.load_json('./config/authenticate.json')['discord-code'])
class Twitter_commands(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

        # config(s)
        self.config = utility.load_json('./config/setup.json')
        self.twitter = utility.load_json('./config/twitter-config.json')

        # interface
        self.color = 0x1e7180
        self.error = 0xcc0000

        self.twitter_auth = twitter.TwitterAuth()

    roles = utility.load_json('./config/roles.json')['discord-roles']

    @commands.command()
    @commands.has_any_role(*roles)
    async def dfa_stats(self, ctx):
        twitter_data = utility.load_json(self.config['twitter'])
        verified = 0
        n_verified = 0

        for v in twitter_data['airdrop-users']:
            id = list(v.keys())[0]

            if v[id][0]['verified'] == True:
                verified += 1
            if v[id][0]['verified'] == False:
                n_verified += 1

        embed = discord.Embed(color=self.color,
                              title=self.config['title'],
                              url=self.config['url'])
        embed.set_thumbnail(url=self.config['thumbnail'])
        embed.add_field(name="Total users registered",
                        value=f"{len(twitter_data['airdrop-users'])}",
                        inline=False)
        embed.add_field(name="Verified", value=f"{verified}", inline=True)
        embed.add_field(name="Non-verified",
                        value=f"{n_verified}",
                        inline=True)
        await ctx.send(embed=embed)

    @commands.command()
    async def register(self, ctx, handle: str):
        registered_users = utility.load_json(self.config['twitter'])
        uuid_2fa = uuid.uuid4().hex
        tmp_twitter = []
        tmp_ids = []

        # store everything in local variables, to be accessed to check if a user has
        # registered already or if the twitter account has already been claimed.
        for i in range(0, len(registered_users['airdrop-users'])):
            for id in registered_users['airdrop-users'][i].keys():
                tmp_ids.append(id)
                tmp_twitter.append(registered_users['airdrop-users'][i][id][0]
                                   ['twitter'][0]['twitter-id'])

        if utility.check_duplicate(str(ctx.message.author.id), tmp_ids):
            embed = discord.Embed(color=self.error)
            embed.set_thumbnail(url=self.config['thumbnail'])
            embed.set_author(name="You have already registered",
                             icon_url=self.config['icon'])
            embed.add_field(name="Information",
                            value="You can only register one twitter account.",
                            inline=True)
            await ctx.author.send(embed=embed)
        else:
            if self.twitter_auth.getUserByName(handle.lower()) == 50:
                embed = discord.Embed(color=self.error)
                embed.set_thumbnail(url=self.config['thumbnail'])
                embed.set_author(name="No account found",
                                 icon_url=self.config['icon'])
                embed.add_field(
                    name="Information",
                    value=
                    "Please check that you have the correct Twitter username.",
                    inline=True)
                await ctx.author.send(embed=embed)
            else:
                if utility.check_duplicate(
                        self.twitter_auth.recipient(handle.lower()),
                        tmp_twitter):
                    embed = discord.Embed(color=self.error)
                    embed.set_thumbnail(url=self.config['thumbnail'])
                    embed.set_author(name="Account already exists",
                                     icon_url=self.config['icon'])
                    embed.add_field(
                        name="Information",
                        value=
                        "Please check you have the correct Twitter username.",
                        inline=True)
                    await ctx.author.send(embed=embed)
                else:
                    d2fa_message = self.twitter_auth.send_disauth(
                        self.twitter_auth.recipient(handle.lower()), uuid_2fa)
                    if d2fa_message == 349:
                        embed = discord.Embed(color=self.error)
                        embed.set_thumbnail(url=self.config['thumbnail'])
                        embed.set_author(name="Unable to send 2FA code",
                                         icon_url=self.config['icon'])
                        embed.add_field(
                            name="Instructions",
                            value=
                            """You will need to adjust your privacy settings to receive the 2FA code.
                                                            **1.** Click on the profile on the top right hand side and click on *"Settings and privacy"*.
                                                            **2.** Next on the left hand pane click *"Privacy and safety"*.
                                                            **3.** You will then see an option under [Direct messages], tick *"Receive Direct Messages from anyone"* and save changed.
                                                            -------------------
                                                            Additionally if you wish to keep your privacy settings how they are you can follow <https://twitter.com/disfactor_auth>
                                                            """,
                            inline=True)
                        await ctx.author.send(embed=embed)

                    else:
                        embed = discord.Embed(color=self.color)
                        embed.set_thumbnail(url=self.config['thumbnail'])
                        embed.set_author(name="Verification sent",
                                         icon_url=self.config['icon'])
                        embed.add_field(
                            name="Instructions",
                            value=
                            f"Check your direct messages via Twitter. Once you obtain the verification code, type ``$verify <code>`` to verify that you are the owner of this account. You must also follow {self.twitter['handle']} on Twitter.",
                            inline=True)
                        await ctx.author.send(embed=embed)

                        parsed_dt = parser.parse(
                            self.twitter_auth.getUserByName(
                                handle.lower())['created_at'])

                        registered_users['airdrop-users'].append(({
                            str(ctx.message.author.id): [{
                                'twitter': [{
                                    'twitter-id':
                                    self.twitter_auth.recipient(
                                        handle.lower()),
                                    'twitter-name':
                                    handle.lower(),
                                    'created-on':
                                    parsed_dt.strftime('%Y-%m-%d %H:%M:%S')
                                }],
                                'discord-name':
                                str(ctx.message.author.name),
                                'verified':
                                False,
                                '2fa-code':
                                uuid_2fa,
                                'timestamp':
                                datetime.today().strftime("%Y-%m-%d %H:%M:%S")
                            }]
                        }))
                        update_json = json.dumps(registered_users)
                        utility.jsonfile(self.config['twitter'], update_json)

    @commands.command()
    async def verify(self, ctx, auth):
        registered_users = utility.load_json(self.config['twitter'])
        tmp_ids = []

        for i in range(0, len(registered_users['airdrop-users'])):
            for id in registered_users['airdrop-users'][i].keys():
                tmp_ids.append(id)

        if utility.check_duplicate(str(ctx.message.author.id), tmp_ids):
            disauth_2fa = registered_users['airdrop-users'][tmp_ids.index(
                str(ctx.message.author.id))][str(str(
                    ctx.message.author.id))][0]['2fa-code']

            if not registered_users['airdrop-users'][tmp_ids.index(
                    str(ctx.message.author.id))][str(str(
                        ctx.message.author.id))][0]['verified']:
                if auth == disauth_2fa:

                    registered_users['airdrop-users'][tmp_ids.index(
                        str(ctx.message.author.id))][str(
                            str(ctx.message.author.id))][0]['verified'] = True

                    update_json = json.dumps(registered_users)
                    utility.jsonfile(self.config['twitter'], update_json)

                    embed = discord.Embed(color=self.color)
                    embed.set_thumbnail(url=self.config['thumbnail'])
                    embed.set_author(name="Registration complete!",
                                     icon_url=self.config['icon'])
                    embed.add_field(
                        name="Information",
                        value=
                        "You can now participate in future airdrops on Discord.",
                        inline=True)
                    await ctx.author.send(embed=embed)

                else:
                    embed = discord.Embed(
                        color=self.error,
                        title=self.config['title'],
                        url=self.config['url'],
                        description=
                        "Invalid 2FA code, please check your twitter direct messages and try again."
                    )
                    embed.set_thumbnail(url=self.config['thumbnail'])
                    await ctx.author.send(embed=embed)

            else:
                embed = discord.Embed(
                    color=self.error,
                    title=self.config['title'],
                    url=self.config['url'],
                    description="You have already verified your account.")
                embed.set_thumbnail(url=self.config['thumbnail'])
                await ctx.author.send(embed=embed)

        else:
            embed = discord.Embed(
                color=self.color,
                title=self.config['title'],
                url=self.config['url'],
                description=
                'No account found. You need to register before verifying.')
            embed.add_field(
                name="Instructions",
                value=
                "When registering make sure you use the following format\n``$register n4dro``",
                inline=True)
            embed.set_thumbnail(url=self.config['thumbnail'])
            await ctx.author.send(embed=embed)

    @commands.command()
    @commands.has_any_role(*roles)
    async def twitter(self, ctx):
        embed = discord.Embed(color=self.color)
        embed.set_thumbnail(url=self.config['thumbnail'])
        embed.set_author(name=self.config['title'],
                         url=self.config['url'],
                         icon_url=self.config['icon'])
        embed.add_field(name="Command",
                        value="$register\n$verify\n$dfa_stats",
                        inline=True)
        embed.add_field(
            name="Description",
            value=
            "Register to participate\nVerify to participate\nView registered stats",
            inline=True)
        await ctx.send(embed=embed)

    # ___- Individual command error handling -___
    @register.error
    async def register_error(self, ctx, error):
        if isinstance(error, commands.MissingRequiredArgument):
            embed = discord.Embed(color=self.error)
            embed.set_thumbnail(url=self.config['thumbnail'])
            embed.set_author(name="No argument given",
                             icon_url=self.config['icon'])
            embed.add_field(
                name="Instructions",
                value=
                "When registering make sure you use the following format\n``$register n4dro``",
                inline=True)
            await ctx.author.send(embed=embed)

    @verify.error
    async def verify_error(self, ctx, error):
        if isinstance(error, commands.MissingRequiredArgument):
            embed = discord.Embed(color=self.error)
            embed.set_thumbnail(url=self.config['thumbnail'])
            embed.set_author(name="No argument given",
                             icon_url=self.config['icon'])
            embed.add_field(
                name="Instructions",
                value=
                "When verifying make sure you use the following format\n``$verify 35204b304795490e8cfca438c2832309``",
                inline=True)
            await ctx.author.send(embed=embed)
    async def register(self, ctx, handle: str):
        registered_users = utility.load_json(self.config['twitter'])
        uuid_2fa = uuid.uuid4().hex
        tmp_twitter = []
        tmp_ids = []

        # store everything in local variables, to be accessed to check if a user has
        # registered already or if the twitter account has already been claimed.
        for i in range(0, len(registered_users['airdrop-users'])):
            for id in registered_users['airdrop-users'][i].keys():
                tmp_ids.append(id)
                tmp_twitter.append(registered_users['airdrop-users'][i][id][0]
                                   ['twitter'][0]['twitter-id'])

        if utility.check_duplicate(str(ctx.message.author.id), tmp_ids):
            embed = discord.Embed(color=self.error)
            embed.set_thumbnail(url=self.config['thumbnail'])
            embed.set_author(name="You have already registered",
                             icon_url=self.config['icon'])
            embed.add_field(name="Information",
                            value="You can only register one twitter account.",
                            inline=True)
            await ctx.author.send(embed=embed)
        else:
            if self.twitter_auth.getUserByName(handle.lower()) == 50:
                embed = discord.Embed(color=self.error)
                embed.set_thumbnail(url=self.config['thumbnail'])
                embed.set_author(name="No account found",
                                 icon_url=self.config['icon'])
                embed.add_field(
                    name="Information",
                    value=
                    "Please check that you have the correct Twitter username.",
                    inline=True)
                await ctx.author.send(embed=embed)
            else:
                if utility.check_duplicate(
                        self.twitter_auth.recipient(handle.lower()),
                        tmp_twitter):
                    embed = discord.Embed(color=self.error)
                    embed.set_thumbnail(url=self.config['thumbnail'])
                    embed.set_author(name="Account already exists",
                                     icon_url=self.config['icon'])
                    embed.add_field(
                        name="Information",
                        value=
                        "Please check you have the correct Twitter username.",
                        inline=True)
                    await ctx.author.send(embed=embed)
                else:
                    d2fa_message = self.twitter_auth.send_disauth(
                        self.twitter_auth.recipient(handle.lower()), uuid_2fa)
                    if d2fa_message == 349:
                        embed = discord.Embed(color=self.error)
                        embed.set_thumbnail(url=self.config['thumbnail'])
                        embed.set_author(name="Unable to send 2FA code",
                                         icon_url=self.config['icon'])
                        embed.add_field(
                            name="Instructions",
                            value=
                            """You will need to adjust your privacy settings to receive the 2FA code.
                                                            **1.** Click on the profile on the top right hand side and click on *"Settings and privacy"*.
                                                            **2.** Next on the left hand pane click *"Privacy and safety"*.
                                                            **3.** You will then see an option under [Direct messages], tick *"Receive Direct Messages from anyone"* and save changed.
                                                            -------------------
                                                            Additionally if you wish to keep your privacy settings how they are you can follow <https://twitter.com/disfactor_auth>
                                                            """,
                            inline=True)
                        await ctx.author.send(embed=embed)

                    else:
                        embed = discord.Embed(color=self.color)
                        embed.set_thumbnail(url=self.config['thumbnail'])
                        embed.set_author(name="Verification sent",
                                         icon_url=self.config['icon'])
                        embed.add_field(
                            name="Instructions",
                            value=
                            f"Check your direct messages via Twitter. Once you obtain the verification code, type ``$verify <code>`` to verify that you are the owner of this account. You must also follow {self.twitter['handle']} on Twitter.",
                            inline=True)
                        await ctx.author.send(embed=embed)

                        parsed_dt = parser.parse(
                            self.twitter_auth.getUserByName(
                                handle.lower())['created_at'])

                        registered_users['airdrop-users'].append(({
                            str(ctx.message.author.id): [{
                                'twitter': [{
                                    'twitter-id':
                                    self.twitter_auth.recipient(
                                        handle.lower()),
                                    'twitter-name':
                                    handle.lower(),
                                    'created-on':
                                    parsed_dt.strftime('%Y-%m-%d %H:%M:%S')
                                }],
                                'discord-name':
                                str(ctx.message.author.name),
                                'verified':
                                False,
                                '2fa-code':
                                uuid_2fa,
                                'timestamp':
                                datetime.today().strftime("%Y-%m-%d %H:%M:%S")
                            }]
                        }))
                        update_json = json.dumps(registered_users)
                        utility.jsonfile(self.config['twitter'], update_json)
    async def verify(self, ctx, auth):
        registered_users = utility.load_json(self.config['twitter'])
        tmp_ids = []

        for i in range(0, len(registered_users['airdrop-users'])):
            for id in registered_users['airdrop-users'][i].keys():
                tmp_ids.append(id)

        if utility.check_duplicate(str(ctx.message.author.id), tmp_ids):
            disauth_2fa = registered_users['airdrop-users'][tmp_ids.index(
                str(ctx.message.author.id))][str(str(
                    ctx.message.author.id))][0]['2fa-code']

            if not registered_users['airdrop-users'][tmp_ids.index(
                    str(ctx.message.author.id))][str(str(
                        ctx.message.author.id))][0]['verified']:
                if auth == disauth_2fa:

                    registered_users['airdrop-users'][tmp_ids.index(
                        str(ctx.message.author.id))][str(
                            str(ctx.message.author.id))][0]['verified'] = True

                    update_json = json.dumps(registered_users)
                    utility.jsonfile(self.config['twitter'], update_json)

                    embed = discord.Embed(color=self.color)
                    embed.set_thumbnail(url=self.config['thumbnail'])
                    embed.set_author(name="Registration complete!",
                                     icon_url=self.config['icon'])
                    embed.add_field(
                        name="Information",
                        value=
                        "You can now participate in future airdrops on Discord.",
                        inline=True)
                    await ctx.author.send(embed=embed)

                else:
                    embed = discord.Embed(
                        color=self.error,
                        title=self.config['title'],
                        url=self.config['url'],
                        description=
                        "Invalid 2FA code, please check your twitter direct messages and try again."
                    )
                    embed.set_thumbnail(url=self.config['thumbnail'])
                    await ctx.author.send(embed=embed)

            else:
                embed = discord.Embed(
                    color=self.error,
                    title=self.config['title'],
                    url=self.config['url'],
                    description="You have already verified your account.")
                embed.set_thumbnail(url=self.config['thumbnail'])
                await ctx.author.send(embed=embed)

        else:
            embed = discord.Embed(
                color=self.color,
                title=self.config['title'],
                url=self.config['url'],
                description=
                'No account found. You need to register before verifying.')
            embed.add_field(
                name="Instructions",
                value=
                "When registering make sure you use the following format\n``$register n4dro``",
                inline=True)
            embed.set_thumbnail(url=self.config['thumbnail'])
            await ctx.author.send(embed=embed)
 def __init__(self, bot):
     self.bot = bot
     self.config = utility_func.load_json('./config/setup.json')
     self.color = 0x1e7180
     self.error = 0xcc0000
Beispiel #11
0
 def __init__(self):
     self.discord_key = utility_func.load_json('./config/tokens.json')
Beispiel #12
0
import sys
import tweepy
import lib.utility_func as utility_func
thrdPartyAuthConfig = utility_func.load_json('./config/authenticate.json')


class TwitterAuth():
    def __init__(self):
        self.auth = tweepy.OAuthHandler(
            thrdPartyAuthConfig['twitter-api_k'],
            thrdPartyAuthConfig['twitter-secret_k'])
        self.auth.set_access_token(thrdPartyAuthConfig['twitter-access'],
                                   thrdPartyAuthConfig['twitter-token'])
        self.api = tweepy.API(self.auth,
                              wait_on_rate_limit=True,
                              parser=tweepy.parsers.JSONParser())

    ##########################################################
    ## GET FUNCTIONS #########################################
    # get details by twitter id: 00112233445566
    def getUserById(self, id):
        try:
            return self.api.get_user(id=id)
        except tweepy.TweepError as error:
            return error.api_code

    # get details by username: @n4dro
    def getUserByName(self, name):
        try:
            return self.api.get_user(screen_name=name)
        except tweepy.TweepError as error:
Beispiel #13
0
import lib.cron as cron
from discord.ext import commands
import lib.utility_func as utility_func

roles = utility_func.load_json('./config/roles.json')['discord-roles']

class cronJob_commands(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.config = utility_func.load_json('./config/setup.json')
        self.twitter = utility_func.load_json('./config/twitter-config.json')
        self.color = 0x1e7180
        self.error = 0xcc0000

    @commands.command()
    @commands.has_any_role(*roles)
    async def setup_batch_cron(self, ctx):
        cron.create_cronjob()

    @commands.command()
    @commands.has_any_role(*roles)
    async def enable_batch_airdrop(self, ctx):
        cron.enable_batch_airdrop()

    @commands.command()
    @commands.has_any_role(*roles)
    async def disable_batch_airdrop(self, ctx):
        cron.disable_batch_airdrop()

def setup(bot):
    bot.add_cog(cronJob_commands(bot))