Beispiel #1
0
    async def set_rally_id(self, ctx):
        member = ctx.author

        with self.update_lock:
            for guild in self.bot.guilds:
                await guild.chunk()

                if not member in guild.members:
                    continue

                role_mappings = list(data.get_role_mappings(guild.id))
                channel_mappings = list(data.get_channel_mappings(guild.id))

                rally_id = data.get_rally_id(member.id)
                if rally_id:
                    balances = rally_api.get_balances(rally_id)
                    for role_mapping in role_mappings:
                        try:
                            await grant_deny_role_to_member(
                                role_mapping, member, balances)
                        except discord.HTTPException:
                            raise errors.RequestError(
                                "network error, try again later")
                        except:
                            # Forbidden, NotFound or Invalid Argument exceptions only called when code
                            # or bot is wrongly synced / setup
                            raise errors.FatalError(
                                "bot is setup wrong, call admin")
                    for channel_mapping in channel_mappings:
                        try:
                            await grant_deny_channel_to_member(
                                channel_mapping, member, balances)
                        except discord.HTTPException:
                            raise errors.RequestError(
                                "network error, try again later")
                        except:
                            # Forbidden, NotFound or Invalid Argument exceptions only called when code
                            # or bot is wrongly synced / setup
                            raise errors.FatalError(
                                "bot is setup wrong, call admin")

            await pretty_print(
                ctx,
                "Command completed successfully!",
                title="Success",
                color=SUCCESS_COLOR,
            )
Beispiel #2
0
 def login_user(self, email, password):
     password_aes = prepare_key(str_to_a32(password))
     uh = stringhash(email, password_aes)
     resp = self.api_request({'a': 'us', 'user': email, 'uh': uh})
     #if numeric error code response
     if isinstance(resp, int):
         raise errors.RequestError(resp)
     self._login_process(resp, password_aes)
Beispiel #3
0
 def parse_url(self, url):
     #parse file id and key from url
     if ('!' in url):
         match = re.findall(r'/#!(.*)', url)
         path = match[0]
         return path
     else:
         raise errors.RequestError('Url key missing')
Beispiel #4
0
    async def convert(self, ctx, argument):
        # Check if argument is a valid location
        valid = weather_api.valid_location(argument)
        if not valid:
            raise errors.InvalidArgument("Invalid location name")

        # Retrieve the current weather data of the location
        data = weather_api.get_current_weather_data(argument)
        if data is None:
            raise errors.RequestError(
                "There was an error while fetching the weather data")

        return {"location_name": argument.capitalize(), "data": data}
Beispiel #5
0
    async def convert(self, ctx, argument):
        # Check if the coin is valid
        valid = coingecko_api.valid_coin(argument)
        if not valid:
            raise errors.InvalidArgument("Invalid coin symbol")

        # Retrieve the price data of the coin
        data = coingecko_api.get_price_data(argument)
        if data is None:
            raise errors.RequestError(
                "There was an error while fetching the coin data")

        return {"symbol": argument.upper(), "data": data}
Beispiel #6
0
    def api_request(self, data):
        params = {'id': self.sequence_num}
        self.sequence_num += 1

        if self.sid:
            params.update({'sid': self.sid})
        req = requests.post(
            '{0}://g.api.{1}/cs'.format(self.schema,self.domain), params=params, data=json.dumps([data]), timeout=self.timeout)
        json_resp = req.json()

        #if numeric error code response
        if isinstance(json_resp, int):
            raise errors.RequestError(json_resp)
        return json_resp[0]
Beispiel #7
0
    async def price(self, ctx, coin: Union[CreatorCoin, CommonCoin, dict]):
        def get_gradient_color(percentage):

            percentage = 50 + int(percentage) / 2
            return gradient(
                Color.red(),
                Color.magenta(),
                Color.lighter_grey(),
                Color.teal(),
                Color.green(),
                percentage=percentage,
            )

        coin_data = coin["data"]

        percentage_24h = coin_data["price_change_percentage_24h"]
        percentage_30d = coin_data["price_change_percentage_30d"]

        if not coin_data:
            raise errors.RequestError(
                "There was an error while fetching the coin data")
        else:
            await pretty_print(
                ctx,
                f"Current Price: {coin_data['current_price']}",
                title="Current Price",
                color=WHITE_COLOR,
            )
            await pretty_print(
                ctx,
                f"{percentage_24h}%",
                title="24H Price Change",
                color=get_gradient_color(percentage_24h),
            )
            await pretty_print(
                ctx,
                f"{percentage_30d}%",
                title="30D Price Change",
                color=get_gradient_color(percentage_30d),
            )